{"id":27874805,"url":"https://github.com/loopeer/attributedstringwrapper","last_synced_at":"2025-05-05T01:38:33.187Z","repository":{"id":56902483,"uuid":"94082385","full_name":"loopeer/AttributedStringWrapper","owner":"loopeer","description":"a simple packaging for NSAttributedString to make the developers easy to use","archived":false,"fork":false,"pushed_at":"2017-09-26T04:42:07.000Z","size":325,"stargazers_count":16,"open_issues_count":0,"forks_count":1,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-05-01T09:49:11.555Z","etag":null,"topics":["carthage","cocoa","cocoapods","ios","nsattributedstring","nsmutableattributedstring","nsmutableparagraphstyle","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/loopeer.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-06-12T10:07:16.000Z","updated_at":"2022-11-17T03:52:46.000Z","dependencies_parsed_at":"2022-08-21T01:50:46.794Z","dependency_job_id":null,"html_url":"https://github.com/loopeer/AttributedStringWrapper","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loopeer%2FAttributedStringWrapper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loopeer%2FAttributedStringWrapper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loopeer%2FAttributedStringWrapper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loopeer%2FAttributedStringWrapper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/loopeer","download_url":"https://codeload.github.com/loopeer/AttributedStringWrapper/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252424966,"owners_count":21745835,"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":["carthage","cocoa","cocoapods","ios","nsattributedstring","nsmutableattributedstring","nsmutableparagraphstyle","swift"],"created_at":"2025-05-05T01:38:32.767Z","updated_at":"2025-05-05T01:38:33.176Z","avatar_url":"https://github.com/loopeer.png","language":"Swift","readme":"# AttributedStringWrapper\n\n\u003cimg src=\"./images/logo.png\" alt=\"AttributedStringWrapper\" title=\"AttributedStringWrapper\"/\u003e\n\n![Xcode 8.3+](https://img.shields.io/badge/Xcode-8.3%2B-blue.svg)\n![iOS 8.0+](https://img.shields.io/badge/iOS-8.0%2B-blue.svg)\n![Swift 3.1+](https://img.shields.io/badge/Swift-3.0%2B-orange.svg)\n[![Version](https://img.shields.io/cocoapods/v/AttributedStringWrapper.svg?style=flat)](https://cocoapods.org/pods/AttributedStringWrapper)\n[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/loopeer/AttributedStringWrapper)\n\u003ca href=\"http://cocoapods.org/pods/AttributedStringWrapper\"\u003e\u003cimg src=\"https://img.shields.io/cocoapods/at/AttributedStringWrapper.svg?label=Apps%20Using%20AttributedStringWrapper\u0026colorB=28B9FE\"\u003e\u003c/a\u003e\n\u003ca href=\"http://cocoapods.org/pods/AttributedStringWrapper\"\u003e\u003cimg src=\"https://img.shields.io/cocoapods/dt/AttributedStringWrapper.svg?label=Total%20Downloads\u0026colorB=28B9FE\"\u003e\u003c/a\u003e\n\n\n\n**AttributedStringWrapper** is a simple packaging for NSAttributedString to make the developers easy to use \n\n\n## Overview\n\n**AttributedStringWrapper**  is base on String extension, converted into `RawRepresentable` protocal in order to solve the question of `Objective-C` namespace.\nSo it looks a bit strange, if you have a better way, please contact me\n\n\n\n#### Before, you may like me\n\n```swift\nextension UILabel {\n    convenience init(frame: CGRect = .zero, attributedText: String, textColor: UIColor, font: UIFont, lineSpacing: CGFloat) {\n        self.init(frame: frame)\n        let paragraphStyle = NSMutableParagraphStyle()\n        paragraphStyle.lineSpacing = lineSpacing\n        paragraphStyle.lineBreakMode = .byTruncatingTail\n        let attrStr = NSAttributedString(string: attributedText, attributes: [NSParagraphStyleAttributeName: paragraphStyle,\n                                                                              NSFontAttributeName: font,\n                                                                              NSForegroundColorAttributeName: textColor])\n        self.attributedText = attrStr\n    }\n}\n\n```\n\n\n```\n        let attr = NSMutableAttributedString(string: content)\n        let paragrap = NSParagraphStyle()\n        paragrap.lineSpacing = 8.0\n        paragrap.alignment = .center\n        attr.addAttributes([NSParagraphStyle: paragrap], range: NSMakeRange(0, attr.length))\n        attr.addAttributes([NSFontAttributeName: UIFont.systemFont(ofSize: 17)], range: NSMakeRange(0, attr.length))\n        let shadow = NSShadow()\n        shadow.shadowColor = UIColor.red\n        shadow.shadowOffset = CGSize(width: 3, height: 3)\n        shadow.shadowBlurRadius = 2.0\n        attr.addAttributes([NSShadowAttributeName: NSShadow], range: NSMakeRange(0, attr.length))\n        label6.attributedText = attr\n\n```\n\n\n#### After: \n\n```swift\n// 1. shadow: you can set range, default allRange\nlabel1.attributedText = content.toAttributed.shadow {\n    $0.shadowColor = UIColor.red\n    $0.shadowOffset = CGSize(width: 3, height: 3)\n    $0.shadowBlurRadius = 2.0\n}.rawValue\n\n\n// 2. paragraphStyle: you can set range, default allRange\n\nlet attrText2 = content.toAttributed.paragraph {\n    $0.alignment = .center\n    $0.lineSpacing = 8.0\n}.font(UIFont.systemFont(ofSize: 15))\n\nlabel2.attributedText = attrText2.rawValue\nprint(attrText2.getHeight(by: screenW - 20))\n\n\n// 3. underLine:  you can set range, default allRange\nlabel3.attributedText = content.toAttributed.underLine(style: [.styleDouble, .patternDot], color: UIColor.red).rawValue\n\n// 4. font, foregroundColor\ntextField.attributedPlaceholder = \"Please enter the phone number\".toAttributed.font(.systemFont(ofSize: 15))\n                                                                 .foregroundColor(.red).rawValue\n\n// 5. Even you can do it\nlabel6.attributedText = content.toAttributed\n            .underLine(style: [.styleSingle, .patternDot], color: .red, range: NSMakeRange(0, 5))\n            .font(.systemFont(ofSize: 18), range: NSMakeRange(5, 5))\n            .backgroundColor(.blue, range: NSMakeRange(10, 5))\n            .foregroundColor(.purple, range: NSMakeRange(15, 5))\n            .baselineOffset(value: 5, range: NSMakeRange(20, 5))\n            .obliqueness(angle: 0.5, range: NSMakeRange(25, 5))\n            .kern(padding: 0.3, range: NSMakeRange(30, 5))\n            .expansion(value: 0.3, range: NSMakeRange(35, 5))\n            .stroke(color: .green, width: 3, range: NSMakeRange(40, 5))\n            .textEffect(range: NSMakeRange(50, 5))\n            .shadow{\n                $0.shadowColor = UIColor.red\n                $0.shadowOffset = CGSize(width: 3, height: 3)\n                $0.shadowBlurRadius = 2.0\n            }.rawValue\n\n// 6. “+”\nlabel7.attributedText = (\"昵称: \".toAttributed.font(UIFont.systemFont(ofSize: 18)).foregroundColor(UIColor.red) +\n                         \"loopeer\".toAttributed.font(UIFont.systemFont(ofSize: 13)).underLine(style: [.styleSingle])).rawValue\n\n\n```\n\n\u003cimg src=\"./images/demo.png\" alt=\"demo\" title=\"demo\"/\u003e\n\n\n\n\n\n\n## Installation\n\n\n### 1. CocoaPods\n\n[CocoaPods](https://cocoapods.org/) is a dependency manager for Cocoa projects.\n\nSpecify AttributedStringWrapper into your project's Podfile:\n\n\n```ruby\n# source 'https://github.com/CocoaPods/Specs.git'\n\nplatform :ios, '8.0'\nuse_frameworks!\n\ntarget '\u003cYour App Target\u003e' do\n  #swift 3.x\n  pod 'AttributedStringWrapper', '~\u003e 1.0.2'  \n  \n  #swift 4.0\n  pod 'AttributedStringWrapper', '~\u003e 1.0.3'\n \nend\n```\n\n\nThen run the following command:\n\n```sh\n$ pod install\n```\n\n\n### 2. Carthage\n\n[Carthage](https://github.com/Carthage/Carthage) is a simple, decentralized\ndependency manager for Cocoa.\n\nSpecify AttributedStringWrapper into your project's Carthage:\n\n\n```\ngithub \"loopeer/AttributedStringWrapper\" ~\u003e 1.0.2\n\n```\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Floopeer%2Fattributedstringwrapper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Floopeer%2Fattributedstringwrapper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Floopeer%2Fattributedstringwrapper/lists"}