{"id":30291300,"url":"https://github.com/kovpas/bostring","last_synced_at":"2025-08-17T00:03:47.142Z","repository":{"id":12274474,"uuid":"14896492","full_name":"kovpas/BOString","owner":"kovpas","description":"Create NSAttributedString like a boss!","archived":false,"fork":false,"pushed_at":"2018-02-05T14:58:22.000Z","size":174,"stargazers_count":192,"open_issues_count":2,"forks_count":16,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-08-17T00:02:22.389Z","etag":null,"topics":["cocoapods","nsattributedstring","objective-c"],"latest_commit_sha":null,"homepage":"","language":"Objective-C","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/kovpas.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":"2013-12-03T14:48:20.000Z","updated_at":"2025-07-04T06:14:16.000Z","dependencies_parsed_at":"2022-09-10T15:01:54.866Z","dependency_job_id":null,"html_url":"https://github.com/kovpas/BOString","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/kovpas/BOString","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kovpas%2FBOString","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kovpas%2FBOString/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kovpas%2FBOString/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kovpas%2FBOString/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kovpas","download_url":"https://codeload.github.com/kovpas/BOString/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kovpas%2FBOString/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270786529,"owners_count":24644567,"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-16T02:00:11.002Z","response_time":91,"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":["cocoapods","nsattributedstring","objective-c"],"created_at":"2025-08-17T00:02:02.512Z","updated_at":"2025-08-17T00:03:47.088Z","avatar_url":"https://github.com/kovpas.png","language":"Objective-C","readme":"NSAttributedString\u0026nbsp;\u0026nbsp;[![Build Status](https://travis-ci.org/kovpas/BOString.png?branch=master)](https://travis-ci.org/kovpas/BOString)\n========\n\nIt's not a secret that NSAttributedString API is far from perfect. Based on NSDictionary, it looks ugly, counter-OOP and hard to maintain...\n\n```obj-c\nNSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:@\"Test attributed string\" attributes:@{NSForegroundColorAttributeName: [UIColor greenColor], NSFontAttributeName: [fnt fontWithSize:20]}];\n[attributedString addAttributes:@{NSForegroundColorAttributeName: [UIColor redColor]\n                                  , NSFontAttributeName: [fnt2 fontWithSize:10]\n                                  , NSLigatureAttributeName: @2\n                                  , NSBaselineOffsetAttributeName: @1}\n                          range:NSMakeRange(3, 5)];\n[attributedString addAttributes:@{NSForegroundColorAttributeName: [UIColor blueColor]\n                                  , NSFontAttributeName: [fnt2 fontWithSize:30]}\n                          range:NSMakeRange(6, 9)];\n[attributedString addAttributes:@{NSStrikethroughStyleAttributeName: @(NSUnderlineStyleSingle)\n                                  , NSStrikethroughColorAttributeName: [UIColor redColor]\n                                  , NSBackgroundColorAttributeName: [UIColor yellowColor]}\n                          range:NSMakeRange(7, 4)];\n_attributedTextView2.attributedText = attributedString;\n```\n\nSome developers get really desperate and write tools like [this](https://itunes.apple.com/us/app/attributed-string-creator/id730928349?mt=12)... Which again proves that NSAttributedString API is far from perfect.\n\nMasonry\n========\n\nI love [masonry](https://github.com/cloudkite/Masonry). I love its clarity, its syntax. If you are using autolayout in your project and still write constraints using NSLayoutConstraint API, you should definitely take a look at masonry. Clear and very brief syntax makes code much more human readable, easy to maintain and modify.\n\nBOString\n========\n\nSo, based on masonry syntax, I decided to create a similar framework, which will take away some pain of creating NSAttributedString:\n\n```obj-c\nNSMutableAttributedString *attributedString = [@\"Test attributed string\" bos_makeString:^(BOStringMaker *make) {\n    make.foregroundColor([UIColor greenColor]);\n    make.font([fnt fontWithSize:20]);\n\n    make.with.range(NSMakeRange(3, 5), ^{\n        make.foregroundColor([UIColor redColor]);\n        make.font([fnt2 fontWithSize:10]);\n        make.ligature(@2);\n        make.baselineOffset(@1);\n    });\n\n    make.with.range(NSMakeRange(6, 9), ^{\n        make.foregroundColor([UIColor blueColor]);\n        make.font([fnt2 fontWithSize:30]);\n    });\n\n    make.with.range(NSMakeRange(7, 4), ^{\n        make.strikethroughStyle(@(NSUnderlineStyleSingle));\n        make.strikethroughColor([UIColor redColor]);\n        make.backgroundColor([UIColor yellowColor]);\n    });\n}];\n```\n\nWhile making a string you can specify ranges for attributes either with a block-based syntax as in the example above:\n\n```obj-c\nmake.with.range(NSMakeRange(6, 9), ^{\n    make.foregroundColor([UIColor blueColor]);\n    make.font([fnt2 fontWithSize:30]);\n});\n```\n\nor set range for a specific attribute (`with` is an optional semantic filler):\n\n```obj-c\nmake.foregroundColor([UIColor blueColor]).with.range(NSRange(6, 9));\nmake.font([fnt2 fontWithSize:30]).range(NSRange(6, 9));\n```\n\nIf you don't specify range, full range of string will be used.\n\nWhich attributes BOString supports? It supports a lot of them:\n\n```obj-c\nfont;\nparagraphStyle;\nforegroundColor;\nbackgroundColor;\nligature;\nkern;\nstrikethroughStyle;\nunderlineStyle;\nstrokeColor;\nstrokeWidth;\nshadow;\ntextEffect;           // iOS only\nattachment;\nlink;\nbaselineOffset;\nunderlineColor;\nstrikethroughColor;\nobliqueness;\nexpansion;\nwritingDirection;\nverticalGlyphForm;\nsuperscript;          // OS X only\ncursor;               // OS X only\ntoolTip;              // OS X only\ncharacterShape;       // OS X only\nglyphInfo;            // OS X only\nmarkedClauseSegment;  // OS X only\ntextAlternatives;     // OS X only\n```\n\n\"Wait, you forgot NSTheVeryBestAndUsefulAttribute!\"\n=======\n\nIndeed, there are many CoreText attributes that are not defined as methods. I.e. `kCTLanguageAttributeName`, `kCTCharacterShapeAttributeName`, `kCTBaselineClassAttributeName`, etc. In this case you may use `attribute` method:\n\n```obj-c\nmake.attribute(kCTLanguageAttributeName, @\"jp\");\n```\n\nEven more than just an NSAttributedString maker!\n=======\n\nA couple of substring attribute setters. Set attributes for a first substring found:\n\n```obj-c\nNSAttributedString *result = [@\"This is a string\" bos_makeString:^(BOStringMaker *make) {\n    make.first.substring(@\"is\", ^{\n        make.foregroundColor([UIColor greenColor]);\n    });\n}];\n```\n\nor highlight every substring:\n\n```obj-c\nNSAttributedString *result = [@\"This is a string\" bos_makeString:^(BOStringMaker *make) {\n    make.each.substring(@\"is\", ^{\n        make.foregroundColor([UIColor greenColor]);\n    });\n}];\n```\n\nYou can also apply attributes using regular expressions:\n\n```obj-c\nNSAttributedString *result = [@\"This is a string\" bos_makeString:^(BOStringMaker *make) {\n    make.each.regexpMatch(@\"\\\\ws\", NSRegularExpressionCaseInsensitive, ^{\n        make.foregroundColor([UIColor greenColor]);\n    });\n}];\n```\n\nOr regular expressions with groups matching:\n\n```obj-c\nNSAttributedString *result = [@\"This is a string\" bos_makeString:^(BOStringMaker *make) {\n    make.first.regexpGroup(@\"[^h](i\\\\w)\\\\s(\\\\w*)\", NSRegularExpressionCaseInsensitive, ^{\n        make.foregroundColor([UIColor greenColor]);\n    });\n}];\n```\n\nShorthand\n=======\n\nIn order to avoid conflicts with any other frameworks, `bos_` prefix is used for category methods. However shorthand methods without this prefix could be used if you add `#define BOS_SHORTHAND` in your `prefix.pch` file before importing `BOString.h`.\n\nDocumentation\n=======\n\nDocumentation in HTML is available [here](http://kovpas.github.io/BOString) or on [cocoadocs.org](http://cocoadocs.org/docsets/BOString).\n\nSupported platforms\n=======\n\n- **iOS 6.0** and later.\n- **OS X Mavericks (10.9)** and later.\n\nShould work fine on iOS 4.3+ and OS X 10.5+ (except of several attributes), but I haven't had a chance to test it.\n\nInstallation\n=======\n\nThe easiest way is to use CocoaPods:\n\nIn your Podfile\n\n`pod 'BOString'`\n\nand import it in a file you want to make strings like a boss:\n\n`#import \"Bostring.h\"`\n\nContribution\n=======\n\nFeel free to submit pull requests into a **separate** branch. Please don't submit pull requests to `master`.\n\nLicense\n=======\n\nBOString is released under the MIT License.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkovpas%2Fbostring","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkovpas%2Fbostring","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkovpas%2Fbostring/lists"}