Latest0.1
Homepagehttps://github.com/strangeliu/AttributeX
LicenseMIT
Platformsios 9.0
Authors

Swift
Carthage compatible

✨ Super sweet syntactic sugar for making strongly-typed AttributedString.

At a Glance

Set attributes with CountableClosedRange

let mAttString = NSMutableAttributedString(string: "AttributeX")
mAttString[0...9].foregroundColor = UIColor.gray
mAttString[0...9].underlineStyle = .styleSingle
mAttString[0...3].underlineColor = UIColor.orange
mAttString[3...9].underlineColor = UIColor.blue.withAlphaComponent(0.5)
mAttString[9...10].foregroundColor = UIColor.red
mAttString[9...10].font = UIFont.boldSystemFont(ofSize: 20)
label.attributedText = mAttString

this can get:

AttributeX

Work with Slice

let detailString = NSMutableAttributedString(string: " Super sweet syntactic sugar for making AttributedString.")
let syntacticSlice = detailString[2...29]
syntacticSlice.foregroundColor = UIColor.red
syntacticSlice.shadow = {
  let shadow = NSShadow()
  shadow.shadowColor = UIColor.blue
  shadow.shadowBlurRadius = 2
  return shadow
}()
let endSlice = detailString[29...detailString.length]
endSlice.baselineOffset = -3
endSlice.foregroundColor = UIColor.lightGray
endSlice.font = UIFont.systemFont(ofSize: 18, weight: .thin)
detailLabel.attributedText = detailString

AttributeX

Latest podspec

{
    "name": "AttributeX",
    "version": "0.1",
    "license": {
        "type": "MIT"
    },
    "homepage": "https://github.com/strangeliu/AttributeX",
    "source": {
        "git": "https://github.com/strangeliu/AttributeX.git",
        "tag": "v0.1"
    },
    "authors": {
        "strangeliu": "[email protected]"
    },
    "summary": "Super sweet syntactic sugar for making AttributedString",
    "platforms": {
        "ios": "9.0"
    },
    "swift_version": "4.1",
    "source_files": "Source/*.{h,m,swift}"
}

Pin It on Pinterest

Share This