https://github.com/status302/CuteAttribute
An elegant way to deal with attributed string in swift.
https://github.com/status302/CuteAttribute
attributedstring ios nsattributedstring nsmutableattributedstring swift-3
Last synced: 6 months ago
JSON representation
An elegant way to deal with attributed string in swift.
- Host: GitHub
- URL: https://github.com/status302/CuteAttribute
- Owner: status302
- License: mit
- Created: 2017-08-13T11:22:33.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2022-06-10T22:47:35.000Z (almost 3 years ago)
- Last Synced: 2024-03-15T09:51:28.467Z (about 1 year ago)
- Topics: attributedstring, ios, nsattributedstring, nsmutableattributedstring, swift-3
- Language: Swift
- Homepage: https://cuteattribute.vsccw.com/
- Size: 623 KB
- Stars: 65
- Watchers: 5
- Forks: 13
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README

CuteAttribute
===
[](https://travis-ci.org/qiuncheng/CuteAttribute)
[](https://github.com/Carthage/Carthage)
[](https://cocoapods.org/pods/CuteAttribute)
[](https://github.com/qiuncheng/CuteAttribute)
[](https://raw.githubusercontent.com/qiuncheng/NoticeBar/master/LICENSE)An elegant way to deal with attributed string in swift. It's convenient to create attributed string by `.cute`, whatever from `String`, `NSString`, `NSAttributedString` or `NSMutableAttributedString`. It's so amazing that almost all methods support `chaining`. I create this project just because I met [Typeset](http://github.com/draveness/typeset) serveral days ago. But I found it's so hard to use by swift. So I made this.

Support
===
Swift 3.0 & iOS 8+Installation
===
#### Swift Package Manager
- add it to your Xcode project.
- Import the header file in your project.```swift
import CuteAttribute
```#### CocoaPods
- add it to your Podfile.```ruby
pod 'CuteAttribute'
```
- Then run the command.```shell
pod install
```
- Import the header file in your project.```swift
import CuteAttribute
```#### Carthage
- Add CuteAttribute to your Cartfile.```ruby
github "qiuncheng/CuteAttribute"
```
- Run the command```shell
carthage update --platform ios
```
- Follow the rest of the [standard Carthage installation](https://github.com/Carthage/Carthage#adding-frameworks-to-an-application) instructions to add CuteAttribute to your project.- Import the header file in your project.
```swift
import CuteAttribute
```#### Manually
- [Download](https://github.com/qiuncheng/CuteAttribute/archive/master.zip) the full file.
- Drag the CuteAttribute folder to your project.Usage
===
### Comparison
attribute name | result | NSAttributedString | CuteAttribute
--- | --- | --- | ---
color |  | NSMutableAttributedString(string: "hello world", attributes: [.foregroundColor: UIColor.red]) | "hello world".cute.matchAll().color(.red)
baselineOffset |  | NSMutableAttributedString(string: "hello world", attributes: [.baselineOffset: 10]) | "hello world".cute.matchAll().baseline(10)
underline |  | NSMutableAttributedString(string: "hello world", attributes: [.underlineColor: UIColor.red, .underlineStyle: NSUnderlineStyle.styleSingle.rawValue]) | "hello world".cute.matchAll().underline(.styleSingle).underlineColor(.red)
font |  | NSMutableAttributedString(string: "hello world", attributes: [NSAttributedStringKey.font: UIFont.systemFont(ofSize: 20)]) | "hello world".cute.matchAll().font(UIFont.systemFont(ofSize: 20))
strikethrough |  | NSMutableAttributedString(string: "hello world", attributes: [.strikethroughStyle: NSUnderlineStyle.styleSingle.rawValue, .strikethroughColor: UIColor.red]) | "hello world".cute.matchAll().strikeThrough(.styleSingle).strokeColor(.red)
link |  | NSMutableAttributedString(string: "hello world", attributes: [.link: "https://blog.vsccw.com"]) | "hello world".cute.matchAll().link("https://blog.vsccw.com")
ligature |  | NSMutableAttributedString(string: "hello world", attributes: [.ligature: 1]) | "hello world".cute.matchAll().ligature(1)
kern |  | NSMutableAttributedString(string: "hello world", attributes: [.kern: 10]) | "hello world".cute.matchAll().kern(10)
stroke |  | NSMutableAttributedString(string: "hello world", attributes: [.strokeColor: UIColor.red, .strokeWidth: 10]) | "hello world".cute.matchAll().strokeColor(.red).strokeWidth(10)
shadow | `let shadow = NSShadow(); shadow.shadowColor = UIColor.red; shadow.shadowOffset = CGSize(width: 4, height: 4); shadow.shadowBlurRadius = 10;`  | NSMutableAttributedString(string: "hello world", attributes: [.shadow: shadow]) | "hello world".cute.matchAll().shadow(shadow)
textEffect |  | "hello world".cute.matchAll().textEffect("NSTextEffectLetterpressStyle") | "hello world".cute.matchAll().textEffect("NSTextEffectLetterpressStyle")
obliqueness |  | NSMutableAttributedString(string: "hello world", attributes: [.obliqueness: 10]) | "hello world".cute.matchAll().obliqueness(10)
expansion |  | NSMutableAttributedString(string: "hello world", attributes: [.expansion: 10]) | "hello world".cute.matchAll().expansion(10)
textAttachment | `let attachment = NSTextAttachment(); attachment.image = UIImage(named: "hello.png");`  | NSMutableAttributedString(string: "hello world", attributes: [.attachment: attachment]) | "hello world".cute.matchAll().textAttachment(attachment)TODO
===
- [x] Documented.
- [x] Example.
- [ ] Test.
- [ ] More convenience.Thanks
===
[Typeset](http://github.com/draveness/typeset) : Deal with AttributedString efficiently in `Objective-C`.LICENCE
===
Under [MIT](https://github.com/qiuncheng/CuteAttribute/blob/master/LICENSE) License