{"id":17046893,"url":"https://github.com/stevebarnegren/attributedstringbuilder","last_synced_at":"2025-04-12T15:30:45.108Z","repository":{"id":22647425,"uuid":"96667725","full_name":"SteveBarnegren/AttributedStringBuilder","owner":"SteveBarnegren","description":"Easily construct attributed strings in swift","archived":false,"fork":false,"pushed_at":"2022-05-17T00:12:11.000Z","size":507,"stargazers_count":78,"open_issues_count":3,"forks_count":14,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-10T04:18:36.820Z","etag":null,"topics":["ios","nsattributedstring","swift"],"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/SteveBarnegren.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":null,"security":null,"support":null}},"created_at":"2017-07-09T07:14:43.000Z","updated_at":"2025-03-08T03:18:40.000Z","dependencies_parsed_at":"2022-08-08T22:30:14.571Z","dependency_job_id":null,"html_url":"https://github.com/SteveBarnegren/AttributedStringBuilder","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SteveBarnegren%2FAttributedStringBuilder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SteveBarnegren%2FAttributedStringBuilder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SteveBarnegren%2FAttributedStringBuilder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SteveBarnegren%2FAttributedStringBuilder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SteveBarnegren","download_url":"https://codeload.github.com/SteveBarnegren/AttributedStringBuilder/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248589273,"owners_count":21129579,"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":["ios","nsattributedstring","swift"],"created_at":"2024-10-14T09:47:45.390Z","updated_at":"2025-04-12T15:30:44.674Z","avatar_url":"https://github.com/SteveBarnegren.png","language":"Swift","readme":"# AttributedStringBuilder\n\n[![Version](https://img.shields.io/cocoapods/v/AttributedStringBuilder.svg?style=flat)](http://cocoapods.org/pods/AttributedStringBuilder)\n[![License](https://img.shields.io/cocoapods/l/AttributedStringBuilder.svg?style=flat)](http://cocoapods.org/pods/AttributedStringBuilder)\n[![Platform](https://img.shields.io/cocoapods/p/AttributedStringBuilder.svg?style=flat)](http://cocoapods.org/pods/AttributedStringBuilder)\n\n**AttributedStringBuilder** takes the pain out of creating *NSAttributedStrings*.\n\n- More readable `NSAttributedString` creation\n- No more faffing about with attribute dictionaries\n- Easliy render images in strings\n- 'Swifty' api\n\n## Usage\n\n### Import the AttributedStringBuilder module\n\n```swift\nimport AttributedStringBuilder\n```\n\n### Creating a string\n\n**AttributedStringBuilder** functions always return the `AttributedStringBuilder` instance that you are using, so you can write concise and readable code by chaining function calls together.\n\nAttributes are defined using enum cases with associated values\n\nDefault attributes can be set, and overriden for selected text portions.\n\n```swift\nlet builder = AttributedStringBuilder()\n\nbuilder.defaultAttributes = [\n    .textColor(UIColor.black),\n    .font( UIFont.systemFont(ofSize: 16, weight: UIFontWeightRegular) ),\n    .alignment(.center),\n]\n\nbuilder\n    .text(\"Attributed strings can make\")\n    .space()\n    .text(\"specific words\", attributes: [.textColor(UIColor.red)])\n    .space()\n    .text(\"pop out\")\n    \nbuilder.attributedString\n```\n\n![Basic Example 1](https://user-images.githubusercontent.com/6288713/28088062-749ad540-667c-11e7-8bc4-cc926a4c8da9.png)\n\n### Another Example\n\nBy chaining method calls together, complex AttributedStrings can be created with just a few lines of code\n\n```swift\nlet builder = AttributedStringBuilder()\nbuilder.defaultAttributes = [\n    .alignment(.center),\n    .textColor(UIColor.orange),\n    .font( UIFont(name: \"AvenirNext-Bold\", size: 30)! )\n]\n\nbuilder\n    .text(\"It's \")\n    .text(\"Easy \", attributes: [.underline(true), .textColor(UIColor.blue)])\n    .text(\"To \", attributes: [.strokeWidth(2), .textColor(UIColor.black)])\n    .text(\"Adjust \", attributes: [.skew(0.3), .textColor(UIColor.magenta)])\n    .text(\"Attributes \", attributes: [.font(UIFont(name: \"Baskerville-Bold\", size: 30)!)])\n\nbuilder.attributedString\n```\n![Basic Example 2](https://user-images.githubusercontent.com/6288713/28088068-7929295e-667c-11e7-9106-d897fe3dc12b.png)\n\n### A More Complex Example\n\n```swift\n// Create an AttributedStringBuilder with default attributes\nlet builder = AttributedStringBuilder()\nbuilder.defaultAttributes = [.alignment(.center)]\n\n// First line attributes\nlet titleAttributes: [AttributedStringBuilder.Attribute] = [\n    .font(UIFont(name: \"Futura-Bold\", size: 40)!),\n    .textColor(UIColor.white),\n    .strokeColor(UIColor.magenta),\n    .strokeWidth(-8),\n    .kerning(5)\n]\n\n// Second Line Attributes\nlet canDoAttributes: [AttributedStringBuilder.Attribute] = [\n    .font(UIFont(name: \"Marker Felt\", size: 30)!),\n    .textColor(UIColor.orange),\n    .kerning(5)\n]\n\n// Third Line Attributes\nlet shadow = NSShadow()\nshadow.shadowColor = UIColor.black\nshadow.shadowBlurRadius = 5\n\nlet awesomeAttributes: [AttributedStringBuilder.Attribute] = [\n    .font(UIFont(name: \"AvenirNext-Bold\", size: 40)!),\n    .textColor(UIColor.yellow),\n    .kerning(5),\n    .shadow(shadow),\n    .skew(0.3),\n    .underline(true)\n]\n\n// Build the string\nbuilder\n    .text(\"ATTRIBUTED STRINGS\", attributes: titleAttributes)\n    .newline()\n    .text(\"Can do\", attributes: canDoAttributes)\n    .newline()\n    .text(\"AWESOME THINGS\", attributes: awesomeAttributes)\n\nbuilder.attributedString\n```\n![Shadow Example](https://user-images.githubusercontent.com/6288713/28088085-7e3f16d8-667c-11e7-806d-b54d8f90d0a2.png)\n\n### Images\n\nIt's easy to render images in your strings, and to adjust the size to fit the uppercase or loowercase height of the font\n\n```swift\nlet font = UIFont.systemFont(ofSize: 90)\n        \nlet builder = AttributedStringBuilder()\nbuilder.defaultAttributes = [\n    .font(font),\n    .underline(true),\n    .textColor(UIColor.purple)\n]\n        \nlet image = UIImage(named: \"PurpleMonster\")!\n        \nbuilder\n    .image(image, withSizeFittingFontUppercase: font)\n    .text(\"Hello\")\n    .image(image, withSizeFittingFontLowercase: font)\n```\n\n![Images Example](https://user-images.githubusercontent.com/6288713/28088088-8117069a-667c-11e7-841d-f67c931a143a.png)\n\n## Installation\n\n##### CocoaPods\n\nAdd the following line to your Podfile:\n\n```ruby\npod \"AttributedStringBuilder\"\n```\n\n##### Manual\n\nCopy ```AttributedStringBuilder.swift``` in to your project\n\n## Who?\n\n[@SteveBarnegren](https://twitter.com/stevebarnegren)\n\n## License\n\nAttributedStringBuilder is available under the MIT license. See the LICENSE file for more info.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstevebarnegren%2Fattributedstringbuilder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstevebarnegren%2Fattributedstringbuilder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstevebarnegren%2Fattributedstringbuilder/lists"}