{"id":2969,"url":"https://github.com/blueapron/styled-text","last_synced_at":"2026-02-23T11:37:36.153Z","repository":{"id":53068549,"uuid":"91494855","full_name":"blueapron/styled-text","owner":"blueapron","description":"Declarative text styles and streamlined Dynamic Type support for iOS","archived":false,"fork":false,"pushed_at":"2022-10-05T00:49:45.000Z","size":3346,"stargazers_count":232,"open_issues_count":1,"forks_count":5,"subscribers_count":14,"default_branch":"master","last_synced_at":"2025-10-23T11:45:20.824Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/blueapron.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":null,"support":null}},"created_at":"2017-05-16T19:09:08.000Z","updated_at":"2025-05-20T09:47:59.000Z","dependencies_parsed_at":"2022-08-26T06:01:27.884Z","dependency_job_id":null,"html_url":"https://github.com/blueapron/styled-text","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/blueapron/styled-text","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blueapron%2Fstyled-text","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blueapron%2Fstyled-text/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blueapron%2Fstyled-text/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blueapron%2Fstyled-text/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/blueapron","download_url":"https://codeload.github.com/blueapron/styled-text/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blueapron%2Fstyled-text/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29741668,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-23T07:44:07.782Z","status":"ssl_error","status_checked_at":"2026-02-23T07:44:07.432Z","response_time":90,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":[],"created_at":"2024-01-05T20:16:27.730Z","updated_at":"2026-02-23T11:37:36.125Z","avatar_url":"https://github.com/blueapron.png","language":"Swift","funding_links":[],"categories":["UI"],"sub_categories":["TextField \u0026 TextView","Other free courses"],"readme":"#  \u003cimg src='https://user-images.githubusercontent.com/4182788/29837864-703557a2-8cc7-11e7-9411-89def22ef0f3.png' width=100 align='center'\u003e   StyledText   [![BuddyBuild](https://dashboard.buddybuild.com/api/statusImage?appID=599b31b30b95740001249898\u0026branch=master\u0026build=latest)](https://dashboard.buddybuild.com/apps/599b31b30b95740001249898/build/latest?branch=master) \nStyledText is a library that simplifies styling dynamic text in iOS applications.  Instead of having to use attributed strings every time you need to update text, you can declaratively set a text style on your labels.  When the text of the label is updated, the label uses the preset style.\n\n\u003cp align='center'\u003e\n\u003cimg src='https://user-images.githubusercontent.com/4182788/28786080-1f616a70-75e6-11e7-84cc-7740406a365b.png' width=300 align='center'\u003e\n\u003c/p\u003e\n\n## Before\n\n``` swift\nlet label = UILabel()\nlet paragraphStyle = NSMutableParagraphStyle()\nparagraphStyle.lineSpacing = 4.0\nlet attributes: [String: Any] = [NSFontAttributeName: UIFont.boldSystemFont(ofSize: 14),\n                                 NSForegroundColorAttributeName: UIColor.blue,\n                                 NSKernAttributeName: 1.5,\n                                 NSParagraphStyleAttributeName: paragraphStyle]\n\nlet string = NSAttributedString(string: \"This is a string\",\n                                attributes: attributes)\nlabel.attributedText = string\nlet newString = NSAttributedString(string: \"This is a new string\",\n                                   attributes: attributes)\nlabel.attributedText = newString\n```\n\n## After\n\n``` swift\nlet styledLabel = StyledLabel()\nstyledLabel.textStyle = TextStyle(font: .boldSystemFont(ofSize: 14), color: .blue, lineSpacing: 4.0, kern: 1.5)\nstyledLabel.text = \"This is a string\"\nstyledLabel.text = \"This is a new string\"\n```\n\n# Installation\n\n1. Add this line to your Podfile:\n\n```\npod \"StyledText\"\n```\n\n2. Run a `pod install`\n3. You're all set!\n\n# How to Use\n\nGetting started with StyledText is easy, just add a `StyledLabel` to your view and provide it with a `TextStyle`.  After that, it behaves like any other `UILabel`.  Changes to the label's `text` property will always use the set `textStyle`.\n\n``` swift\nclass ViewController: UIViewController {\n    private let styledLabel: StyledLabel = {\n        let label = StyledLabel(frame: .zero)\n        label.textStyle = TextStyle(font: .boldSystemFont(ofSize: 24.0),\n                                    color: .orange)\n        return label\n    }()\n}\n```\n\n## TextStyle\n\nA `TextStyle` represents the attributes a styled view should use to draw its text.  Many different text formatting options are supported, including those that previously required interaction with attributed strings or paragraph styles, such as kerning and line spacing.  Creating a `TextStyle` is easy, just specify a font along with any other attributes you want to define.  Any unspecified attributes simply remain as system defaults.\n\n``` swift\nlet style = TextStyle(font: .italicSystemFont(ofSize: 72),\n                      color: .magenta,\n                      lineSpacing: 10,\n                      lineHeightMultiple: 2.0,\n                      kern: -0.5,\n                      alignment: .left,\n                      lineBreakMode: .byTruncatingMiddle)\n\nlet blueStyle = style.with(color: .blue)\nlet redStyle = style.with(color: .red)\n```\n\n## Providing Defaults\n\nYou probably have a sensible default value for kerning that works well for your font.  Instead of needing to specify this kern value in each individual `TextStyle` you create, you can use a `TextStyleDefaultsGenerator` to add it automatically.  The simplest way to get started with this is to extend `TextStyle` to conform to the `TextStyleDefaultsGenerator` protocol, the library will detect if you've added this conformance and behave appropriately.\n\n``` swift\nextension TextStyle: TextStyleDefaultsGenerator {\n    private static let defaultCeraKern: CGFloat = -0.2\n    private static let defaultChronicleKern: CGFloat = -0.2\n\n    static public func defaultKern(for font: UIFont) -\u003e CGFloat? {\n        if font.fontName.contains(\"Cera\") {\n            return defaultCeraKern\n        } else if font.fontName.contains(\"Chronicle\") {\n            return defaultChronicleKern\n        }\n        return nil\n    }\n}\n```\n\n## Dynamic Type Support\n\n\u003cp align='center'\u003e\n\u003cimg src='https://user-images.githubusercontent.com/4182788/28786100-2fd9c528-75e6-11e7-8c5d-935598cf5147.gif' width=300 align='center'\u003e\n\u003c/p\u003e\n\nStyledText supports scaling text content to the system font size, a feature Apple calls [Dynamic Type](https://useyourloaf.com/blog/supporting-dynamic-type/).  To use this feature, set the `dynamicTypeBehavior` property of a `TextStyle` to one of these values:\n\n* `noScaling`: [default] keep the font size constant, even when the system font size changes\n* `scaleToStandardSizes`: scale the font to all standard system font sizes, larger accessibility sizes are capped at the maximum standard size\n* `scaleToAllSizes`: scale the font to all standard and accessiblity font sizes\n\nIt's possible for the font size to change while your application is running.  When this occurs, you'll need to call `refreshStyle()` on any styled components that are visible for the size to update.  A good way to listen for this event is by adding a delegate to the shared `DynamicTypeController`:\n\n```swift\nclass MyViewController: UIViewController, DynamicTypeControllerDelegate {\n    let label: StyledLabel = {\n        let label = StyledLabel()\n        label.textStyle = TextStyle(font: .boldSystemFont(ofSize: 14), color: .black, dynamicTypeBehavior: .scaleToStandardSizes)\n        return label\n    }()\n\n    override func viewDidLoad() {\n        super.viewDidLoad()\n\n        DynamicTypeController.shared.addDelegate(self)\n    }\n\n    func preferredContentSizeCategoryDidUpdate(controller: DynamicTypeController, newCategory: UIContentSizeCategory){\n        label.refreshStyle()\n    }\n}\n```\n\n## Styled Components\n\nTo enable automatic styling, StyledText uses a number of view subclasses that are simple swap-in replacements for conventional UIKit components.\n\n| StyledText View | Replaces UIKit View |\n| --------------- | ------------------- |\n| StyledLabel     | UILabel             |\n| StyledTextView  | UITextView          |\n| StyledButton*   | UIButton            |\n\n### [*] Using StyledButton\n\n`StyledButton` provides text style properties for each `UIControlState` button state.\n\n| Control State | Text Style Property  |\n| ------------- | -------------------- |\n| .normal       | normalTextStyle      |\n| .highlighted  | highlightedTextStyle |\n| .disabled     | disabledTextStyle    |\n| .selected     | selectedTextStyle    |\n\n# License\n\nStyledText 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%2Fblueapron%2Fstyled-text","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fblueapron%2Fstyled-text","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblueapron%2Fstyled-text/lists"}