{"id":18048772,"url":"https://github.com/farzadshbfn/styled","last_synced_at":"2025-04-10T09:53:04.606Z","repository":{"id":56922232,"uuid":"216269724","full_name":"farzadshbfn/Styled","owner":"farzadshbfn","description":"Elegant Style(Color,Font,Image,...) management in Swift","archived":false,"fork":false,"pushed_at":"2021-03-17T19:55:33.000Z","size":600,"stargazers_count":36,"open_issues_count":3,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-24T08:47:51.151Z","etag":null,"topics":["accessibility","assets","localization","string-interpolation","style","swift","theme"],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/farzadshbfn.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-10-19T20:58:24.000Z","updated_at":"2025-03-03T16:16:12.000Z","dependencies_parsed_at":"2022-08-20T22:20:26.068Z","dependency_job_id":null,"html_url":"https://github.com/farzadshbfn/Styled","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/farzadshbfn%2FStyled","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/farzadshbfn%2FStyled/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/farzadshbfn%2FStyled/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/farzadshbfn%2FStyled/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/farzadshbfn","download_url":"https://codeload.github.com/farzadshbfn/Styled/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248198229,"owners_count":21063626,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["accessibility","assets","localization","string-interpolation","style","swift","theme"],"created_at":"2024-10-30T20:15:10.247Z","updated_at":"2025-04-10T09:53:04.573Z","avatar_url":"https://github.com/farzadshbfn.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Styled\n\n[![Version](https://img.shields.io/cocoapods/v/Styled.svg?style=flat)](https://cocoapods.org/pods/Styled)\n[![License](https://img.shields.io/cocoapods/l/Styled.svg?style=flat)](https://cocoapods.org/pods/Styled)\n[![Platform](https://img.shields.io/cocoapods/p/Styled.svg?style=flat)](https://cocoapods.org/pods/Styled)\n\nStyled is a Type-Safe accessibility \u0026 theme management library in Swift.\n\n\u003cimg src=\"https://raw.githubusercontent.com/farzadshbfn/Styled/master/Light.png\" width=\"320\"\u003e\u003cimg src=\"https://raw.githubusercontent.com/farzadshbfn/Styled/master/Dark.png\" width=\"320\"\u003e\n\n* [Features](#Features)\n* [Requirements](#Requirements)\n* [Installation](#Installation)\n  * [CocoaPods](#Cocoapods)\n* [Example](#Example)\n* [Usage](#Usage)\n  * [Colors](#Colors)\n  * [Fonts](#Fonts)\n  * [Images](#Images)\n  * [LocalizedString](#LocalizedString)\n\n## Features\n\n* Color management \u0026 synchronization with OS\n* Font management \u0026 synchronization with OS\n* String-Interpolation Localization\n* Image management (per Localization or provided lazily by an external resource)\n\n## Requirements\n\n* iOS 10.0+\n* XCode 11+\n* Swift 5.1+ (Swift 5.0 compatible)\n\n## Installation\n\n### CocoaPods\n\n[CocoaPods](https://cocoapods.org) is a dependency manager for Cocoa projects. For usage and installation instructions, visit their website. To integrate **Styled**\ninto your XCode project, simply add the Styled dependency to your Podfile.\n\n```ruby\npod 'Styled'\n```\n\n### Carthage\n\nComing soon\n\n### Swift Package Manager\n\nComing soon\n\n## Example\n\nTo run the example project, clone the repo, and run `pod install` from the root directory.\n\n\u003e Don't forget to play with XCode accessibilities to see the results\n\n## Usage\n\n### Colors\n\nThis is how you'll be using Styled in a nutshell:\n\n```swift\nclass CustomView: UIView {\n    var customColor: UIColor { didSet { /* Update UI Accordingly */ } }\n}\n\nlet view = CustomView()\n\n/// This is where all the magic happens\nview.sd.backgroundColor = .background\n\n/// It even works with custom defined variables 🤩\nview.sd.customColor = .red\n\n/// It also supports transformations 👽\nview.sd.customColor = .blending(.red, with: .black) // Darkened red\n```\n\nJust by writing `view.sd.customColor` Styled will gaurantee that everytime the `ColorScheme` changes, your `customColor` will get updated accordingly in the background, So you no longer need to worry about choosing the correct color or updating your UI everytime user changes accessibility options (Dark mode, font size, High contrast, etc).\n\n---\n\nThis is how you define `Color`s:\n\n```swift\nextension Color {\n    /// Color suitable for first-level labels\n    static let label: Self = \"label\"\n\n    /// Color suitable for second-level labels (i.e subtitle/description)\n    static let secondaryLabel: Self = \"label.secondary\"\n\n    /// Or custimized **red** for different schemes?\n    static let red: Color = \"red\"\n}\n\n```\n\nAnd this is how you define `ColorScheme`s:\n\n```swift\nextension Color {\n    struct LightScheme: ColorScheme {\n        func color(for color: Color) -\u003e UIColor? {\n            switch color {\n            case .label: return UIColor.black\n            case .secondaryLabel: return UIColor.gray\n            default: fatalError(\"Uknown color \\(color)\")\n            }\n        }\n    }\n\n    struct DarkColorScheme: ColorScheme { ... }\n}\n```\n\nAnd this is how you control which `ColorScheme` the app should use:\n\n```swift\n// You can manually control the ColorScheme\nStyled.Config.colorScheme = Color.LightScheme()\n\n// Or You can update it with system's theme\nStyled.Config.onUserInterfaceStyleDidChange {\n    switch $0 {\n    case .dark: return .replace(with: Color.DarkScheme())\n    default: return .replace(with: Color.LightScheme())\n    }\n}\n\n// Or if you defined your colors in AssetsCatalog:\nStyled.Config.colorScheme = Color.DefaultScheme()\n```\n\nAnd That's it! You can also take the same approach to define `Image`s, `Font`s and `LocalizedString`s.\n\n### Fonts\n\nDefining `Font`s and `FontScheme`s is almost the same as defining [Colors](#Colors).\nFor keeping the application in sync with device's font size, you can use the following method:\n\n```swift\nStyled.Config.onContentSizeCategoryDidChange { _ in .update }\n```\n\n`.update` will not change the current `FontScheme`, but will trigger a font update on all Styled elements.\n\n### Images\n\nDefining `Image`s and `ImageScheme`s is the same as defining [Colors](#Colors).\n\n### LocalizedString\n\n`LocalizedString` by default will look inside `Localizable.strings` \u0026 `Localizable.stringsdict`, but you can take ownership of Localization management just like `Color`s/`Font`s/`Image`s by defining your own `LocalizedStringScheme`s.\n\nYou can also define common words or sentences that you use throughout the application just like Color:\n\n```swift\nextension LocalizedString {\n    static let ok: LocalizedString = \"ok\"\n    static let cancel: LocalizedString = \"cancel\"\n}\n```\n\nAnd just use it like other Styled variables:\n\n```swift\nlabel.sd.text = .ok\n```\n\n#### String-Interpolation\n\n`LocalizedString` also supports string-interpolation to translate localizations.\n\n**By default all interpolations will be replaced with `\"%@\"` before being queried**\n\nFor example the following interpolation:\n\n```swift\nlabel.sd.text = \"lastIndex is \\(count - 1))\"\n```\n\nWill look inside `Localizable.strings` (or `Localizable.stringsdict` or your personalized `LoaclizedStringScheme`) for the key `\"lastIndex is %@\"`  to fetch its translation. So this is what inside `Localizable.strings` file should look like:\n\n```swift\n// English\n\"lastIndex is %@\" = \"lastIndex is %@\";\n\n// Persian\n\"lastIndex is %@\" = \"آخرین اندیس %@ است\";\n```\n\nYou can also customize the specifier inside the interpolation method to use something else instead of `\"%@\"`:\n\n```swift\nlabel.sd.text = \"lastIndex is \\(count - 1, specifier: \"%d\")\"\n```\n\nAnd this will generate the key `\"lastIndex is %d\"`\n\nYou can always add your personalized functionalities to the `LocalizedString.StringInterpolation` to make your String-Interpolation localization suit your needs.\n\n## Author\n\n[FarzadShbfn](https://twitter.com/FarzadShbfn), farzad.shbfn@gmail.com\n\n## License\n\nStyled is available under the MIT license. See the LICENSE file for more info.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffarzadshbfn%2Fstyled","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffarzadshbfn%2Fstyled","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffarzadshbfn%2Fstyled/lists"}