{"id":13466185,"url":"https://github.com/rosberry/texstyle","last_synced_at":"2025-10-07T01:11:01.214Z","repository":{"id":45831089,"uuid":"183414619","full_name":"rosberry/texstyle","owner":"rosberry","description":"Format iOS attributed strings easily","archived":false,"fork":false,"pushed_at":"2022-09-12T01:45:11.000Z","size":870,"stargazers_count":79,"open_issues_count":3,"forks_count":22,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-10-29T19:17:20.727Z","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/rosberry.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-04-25T10:46:53.000Z","updated_at":"2024-03-31T13:01:15.000Z","dependencies_parsed_at":"2022-09-15T02:40:33.464Z","dependency_job_id":null,"html_url":"https://github.com/rosberry/texstyle","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rosberry%2Ftexstyle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rosberry%2Ftexstyle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rosberry%2Ftexstyle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rosberry%2Ftexstyle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rosberry","download_url":"https://codeload.github.com/rosberry/texstyle/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228114885,"owners_count":17871742,"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":[],"created_at":"2024-07-31T15:00:40.548Z","updated_at":"2025-10-07T01:11:01.159Z","avatar_url":"https://github.com/rosberry.png","language":"Swift","funding_links":[],"categories":["Libs","Text [🔝](#readme)"],"sub_categories":["Text"],"readme":"\u003cp align=\"center\"\u003e\n    \u003cimg src=\"https://raw.githubusercontent.com/rosberry/texstyle/master/.github/texstyle_logo.png\" width=\"528\" max-width=\"90%\" alt=\"Stylin\" /\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://github.com/rosberry/texstyle/actions\"\u003e\n      \u003cimg src=\"https://github.com/rosberry/texstyle/workflows/Build/badge.svg\" /\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://swift.org/\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/swift-5.0-orange.svg\" alt=\"Swift Version\" /\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://github.com/Carthage/Carthage\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/Carthage-compatible-green.svg\" alt=\"Carthage Compatible\" /\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://codecov.io/gh/rosberry/texstyle\"\u003e\n        \u003cimg src=\"https://codecov.io/gh/rosberry/texstyle/branch/master/graph/badge.svg\" alt=\"codecov\" /\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\nTexstyle allows you to format attributed strings easily.\n\n## Features\n\n- Applying attributes with strong typing and autocompletion\n- Cache for attributes\n- Substyles\n- Convenient extensions for `String` and `UIButton`\n\n## Requirements\n\n- iOS 9.0+ / tvOS 9.0+\n- Xcode 10.0+\n\n## Usage\n\nHere is a basic example of Texstyle using:\n\n```swift\nlet text = Text(value: \"Hello, World 🌍\", style: .title1)\ntext.add(.heading1, for: \"World\")\ntitleLabel.attributedText = text.attributed\n```\n\nThe result:\n\n![Example1](https://raw.githubusercontent.com/rosberry/texstyle/master/.github/example1.png)\n\nLet's start with text styles. There is a `TextStyle` class for configuring different style parameters like font, color, kerning etc. We prefer to use `TextStyle` extension for app specific styles:\n\n```swift\nextension TextStyle {\n\n    static let title1: TextStyle = {\n        let style = TextStyle()\n        style.font = .systemFont(ofSize: 32, weight: .regular)\n        return style\n    }()\n        \n    static let heading1: TextStyle = {\n        let style = TextStyle()\n        style.font = .systemFont(ofSize: 28, weight: .semibold)\n        style.color = .purple\n        return style\n    }()\n}\n```\n\nIt allows you to reuse the styles across the app.\n\nNext, create a `Text` instance. It contains string value and style:\n\n```swift\nlet text = Text(value: \"Hello, World 🌍\", style: .title1)\n```\n\nText also supports independent styles for each `UIControl.State`. For example, if you want to use a different style for button highlight state, you should initialize text like:\n\n```swift\nlet text = Text(value: \" Sign in with Apple\", styles: [.normal: .heading1,\n                                                         .highlighted: .heading2])\n```\n\nTo create an attributed string, just use:\n\n```swift\n//By default for normal state\ntext.attributed\n\n//For needed state\ntext.attributed(for: .highlighted)\n```\n\nAll attributed strings are cached by default. It's useful in reusable elements like `UICollectionViewCell` or `UITableViewCell`.\n\nThere are custom operators for texts and strings:\n\n```swift\nlet text1 = Text(value: \"Ros\", style: .title1)\nlet text2 = text1 + \"ber\"\nlet text3 = Text(value: \"ry\", style: .title1)\nlet text4 = text2 + text3\ntext4.value // \"Rosberry\"\n```\n\nThere are convenience APIs for text creation and applying:\n\n```swift\n//String to text\n\"Settings\".text(with: .heading1)\n\n//UIButton\nbutton.setText(text)\n```\n\nCheck [TexstyleExample](xcode://clone?repo=https%3A%2F%2Fgithub.com%2Frosberry%2Ftexstyle) project for more examples.\n\n![Example2](https://raw.githubusercontent.com/rosberry/texstyle/master/.github/example2.png)\n\n## Cache\n\nTextStyle and Text classes have internal cache to prevent extra calculation. TextStyle caches attributes and invalidates it on any attribute change. Text has cached attributed strings for states. For example, if you use texts in collection view cells and want to update some labels in it after reuse, texts return cached strings. Please note that texts won't invalidate cached strings if you update textstyle attributes.\n\n## Installation\n\n### Depo\n\n[Depo](https://github.com/rosberry/depo) is a universal dependency manager that combines Carthage, SPM and CocoaPods and provides common user interface to all of them.\n\nTo install `Texstyle` via Carthage using Depo you need to add this to your `Depofile`:\n```yaml\ncarts:\n  - kind: github\n    identifier: rosberry/Texstyle\n```\n\n\u003cdetails\u003e\n  \u003csummary\u003eTo install Texstyle via CocoaPods\u003c/summary\u003e\n  Add this to your Depofile:\n\n  ```yaml\n  pods:\n    - name: Texstyle\n  ```\n\u003c/details\u003e\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 Alamofire into your Xcode project using CocoaPods, specify it in your `Podfile`:\n\n```ruby\npod 'Texstyle', '~\u003e 0.0'\n```\n\n### Carthage\n\n[Carthage](https://github.com/Carthage/Carthage) is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks. To integrate Alamofire into your Xcode project using Carthage, specify it in your `Cartfile`:\n\n```ogdl\ngithub \"Rosberry/Texstyle\" ~\u003e 5.0\n```\n\n## Documentation\n\nRead the [docs](https://rosberry.github.io/texstyle). Generated with [jazzy](https://github.com/realm/jazzy). Hosted by [GitHub Pages](https://pages.github.com).\n\n## About\n\n\u003cimg src=\"https://github.com/rosberry/Foundation/blob/master/Assets/full_logo.png?raw=true\" height=\"100\" /\u003e\n\nThis project is owned and maintained by [Rosberry](http://rosberry.com). We build mobile apps for users worldwide 🌏.\n\nCheck out our [open source projects](https://github.com/rosberry), read [our blog](https://medium.com/@Rosberry) or give us a high-five on 🐦 [@rosberryapps](http://twitter.com/RosberryApps).\n\n## License\n\nTexstyle 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%2Frosberry%2Ftexstyle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frosberry%2Ftexstyle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frosberry%2Ftexstyle/lists"}