{"id":2010,"url":"https://github.com/zats/Tribute","last_synced_at":"2025-08-02T05:33:34.014Z","repository":{"id":43801291,"uuid":"47514067","full_name":"zats/Tribute","owner":"zats","description":"Programmatic creation of NSAttributedString doesn't have to be a pain","archived":false,"fork":false,"pushed_at":"2022-02-18T15:22:59.000Z","size":2493,"stargazers_count":64,"open_issues_count":0,"forks_count":10,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-12-06T09:35:02.137Z","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/zats.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-12-06T21:14:58.000Z","updated_at":"2024-09-17T01:43:39.000Z","dependencies_parsed_at":"2022-09-12T22:11:36.346Z","dependency_job_id":null,"html_url":"https://github.com/zats/Tribute","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/zats/Tribute","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zats%2FTribute","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zats%2FTribute/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zats%2FTribute/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zats%2FTribute/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zats","download_url":"https://codeload.github.com/zats/Tribute/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zats%2FTribute/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268339406,"owners_count":24234544,"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","status":"online","status_checked_at":"2025-08-02T02:00:12.353Z","response_time":74,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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:01.172Z","updated_at":"2025-08-02T05:33:33.266Z","avatar_url":"https://github.com/zats.png","language":"Swift","funding_links":[],"categories":["UI","Text"],"sub_categories":["Layout","Other free courses","Other Testing","Keychain"],"readme":"# Tribute [![Build Status](https://travis-ci.org/zats/Tribute.svg?branch=master)](https://travis-ci.org/zats/Tribute)\n\n```swift\nlet string = NSMutableAttributedString().add(\"Hello \") {\n    $0.font = .systemFontOfSize(20)\n    $0.color = .redColor()\n    $0.underline = .StyleSingle\n}.add(\"world \") {\n    $0.stroke = .Filled(width: 2)\n    $0.strokeColor = .orangeColor()\n}.add(\"of Swift \"){\n    $0.font = .systemFontOfSize(12)\n    $0.underline = nil\n    $0.URL = NSURL(string: \"http://swift.org\")!\n}.add(UIImage(named: \"swift\")!)\n```\n\n![](https://raw.githubusercontent.com/zats/Tribute/master/docs/attributed-string.png)\n\nNot bad comparing to\n\n```swift\nlet string2 = NSMutableAttributedString()\nstring2.appendAttributedString(NSAttributedString(string: \"Hello \", attributes: [\n    NSFontAttributeName: UIFont.systemFontOfSize(20),\n    NSUnderlineStyleAttributeName: NSUnderlineStyle.StyleSingle.rawValue,\n    NSForegroundColorAttributeName: UIColor.redColor()\n]))\nstring2.appendAttributedString(NSAttributedString(string: \"world \", attributes: [\n    NSFontAttributeName: UIFont.systemFontOfSize(20),\n    NSUnderlineStyleAttributeName: NSUnderlineStyle.StyleSingle.rawValue,\n    NSForegroundColorAttributeName: UIColor.redColor(),\n    NSStrokeColorAttributeName: UIColor.orangeColor(),\n    NSStrokeWidthAttributeName: -2\n]))\nstring2.appendAttributedString(NSAttributedString(string: \"of Swift \", attributes: [\n    NSFontAttributeName: UIFont.systemFontOfSize(12),\n    NSForegroundColorAttributeName: UIColor.redColor(),\n    NSStrokeColorAttributeName: UIColor.orangeColor(),\n    NSStrokeWidthAttributeName: -2\n]))\nlet attachment = NSTextAttachment()\nattachment.image = UIImage(named: \"swift\")\nstring2.appendAttributedString(NSAttributedString(attachment: attachment))\n```\n\n# Design Goals\n\n1. Word processor logic: appending a string should inherit last attributes.\n1. Allow for easy customization of common properties, including toggle bold or change the font size.\n1. Flatten paragraph style and attributes, no more 5 lines of code if all you wanted is to change text alignment.\n1. Replace weird attributes with more reasonable versions (for example [`Attribute.Stroke`](https://github.com/zats/Tribute/blob/master/Tribute/Tribute.swift#L24-L27) vs [NSStrokeWidthAttributeName](https://developer.apple.com/library/mac/qa/qa1531/_index.html)).\n1. Minimal overhead: produce only required attributes.\n1. Have an attributed string ready to use every time you leave the configuration block.\n1. Replace string constants with strongly typed enums where possible.\n\n# Notes\n\n## Playground\n\nPlaygrounds do not always render `NSAttributesString` correctly (font variations and attachments are few of the problematic I noticed). \n\n**Workaround**: Use a `UILabel` as a live view instead: `XCPlaygroundPage.currentPage.liveView = label`.\n\n## Font variations\n\nNot all fonts have both italic and bold variations\n\n**Workaround**: Use `obliqueness` property as a poor man italic, and `expansion` as a bold respectively.\n\n## Closure with one statement\n\nWhen the configuration closure includes only one statement, compiler gets confused\n\n**Workaround**: Specify closure type explicitly like so\n\n```swift \nstring.add(\"text\") { (inout a: Attributes) in\n    a.color = .redColor()\n}\n```\n\nIf you know a better way, please open a PR, I'd love to learn from it!\n\n# Roadmap\n\n- [ ] Objective-C compatibility\n- [ ] Moar attributes (PRs are welcome)\n\n*This is just a tribute*\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzats%2FTribute","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzats%2FTribute","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzats%2FTribute/lists"}