Latest 1.2.4
Homepage https://github.com/qiuncheng/CuteAttribute
License MIT
Platforms ios 8.0, requires ARC
Frameworks UIKit
Authors

CuteAttribute
CuteAttribute

Build Status
Carthage compatible
pod version
CuteAttribute
GitHub 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 serveral days ago. But I found it’s so hard to use by swift. So I made this.

CuteAttribute

Support

Swift 3.0 & iOS 8+

Installation

CocoaPods

  • add it to your Podfile.
pod 'CuteAttribute'
  • Then run the command.
pod install
  • Import the header file in your project.
import CuteAttribute

Carthage

  • Add CuteAttribute to your Cartfile.
github "qiuncheng/CuteAttribute"
  • Run the command
carthage update --platform ios
import CuteAttribute

Manually

  • Download the full file.
  • Drag the CuteAttribute folder to your project.

Usage

Comparison

attribute name result NSAttributedString CuteAttribute
color CuteAttribute NSMutableAttributedString(string: "hello world", attributes: [.foregroundColor: UIColor.red]) "hello world".cute.matchAll().color(.red)
baselineOffset CuteAttribute NSMutableAttributedString(string: "hello world", attributes: [.baselineOffset: 10]) "hello world".cute.matchAll().baseline(10)
underline CuteAttribute NSMutableAttributedString(string: "hello world", attributes: [.underlineColor: UIColor.red, .underlineStyle: NSUnderlineStyle.styleSingle.rawValue]) "hello world".cute.matchAll().underline(.styleSingle).underlineColor(.red)
font CuteAttribute NSMutableAttributedString(string: "hello world", attributes: [NSAttributedStringKey.font: UIFont.systemFont(ofSize: 20)]) "hello world".cute.matchAll().font(UIFont.systemFont(ofSize: 20))
strikethrough CuteAttribute NSMutableAttributedString(string: "hello world", attributes: [.strikethroughStyle: NSUnderlineStyle.styleSingle.rawValue, .strikethroughColor: UIColor.red]) "hello world".cute.matchAll().strikeThrough(.styleSingle).strokeColor(.red)
link CuteAttribute NSMutableAttributedString(string: "hello world", attributes: [.link: "https://blog.vsccw.com"]) "hello world".cute.matchAll().link("https://blog.vsccw.com")
ligature CuteAttribute NSMutableAttributedString(string: "hello world", attributes: [.ligature: 1]) "hello world".cute.matchAll().ligature(1)
kern CuteAttribute NSMutableAttributedString(string: "hello world", attributes: [.kern: 10]) "hello world".cute.matchAll().kern(10)
stroke CuteAttribute 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; CuteAttribute NSMutableAttributedString(string: "hello world", attributes: [.shadow: shadow]) "hello world".cute.matchAll().shadow(shadow)
textEffect no image "hello world".cute.matchAll().textEffect("NSTextEffectLetterpressStyle") "hello world".cute.matchAll().textEffect("NSTextEffectLetterpressStyle")
obliqueness CuteAttribute NSMutableAttributedString(string: "hello world", attributes: [.obliqueness: 10]) "hello world".cute.matchAll().obliqueness(10)
expansion CuteAttribute NSMutableAttributedString(string: "hello world", attributes: [.expansion: 10]) "hello world".cute.matchAll().expansion(10)
textAttachment let attachment = NSTextAttachment(); attachment.image = UIImage(named: "hello.png"); CuteAttribute NSMutableAttributedString(string: "hello world", attributes: [.attachment: attachment]) "hello world".cute.matchAll().textAttachment(attachment)

TODO

  • [x] Documented.
  • [x] Example.
  • [ ] Test.
  • [ ] More convenience.

Thanks

Typeset : Deal with AttributedString efficiently in Objective-C.

LICENCE

Under MIT License

Latest podspec

{
    "name": "CuteAttribute",
    "version": "1.2.4",
    "summary": "A elegant way to use attributed string in swift.",
    "description": "* A elegant way to deal with attributed string in swift. n* It's convenient to create attributed string by `.cute`, n* whatever from `String`, `NSString`, `NSAttributedString` or `NSMutableAttributedString`. n* It's so amazing that almost all method support `chaining`.",
    "homepage": "https://github.com/qiuncheng/CuteAttribute",
    "license": "MIT",
    "authors": {
        "qiuncheng": "[email protected]"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source": {
        "git": "https://github.com/qiuncheng/CuteAttribute.git",
        "tag": "1.2.4"
    },
    "source_files": "CuteAttribute/*.{swift,h}",
    "frameworks": "UIKit",
    "requires_arc": true
}

Pin It on Pinterest

Share This