delba / TextAttributes

An easier way to compose attributed strings

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to set the range?

qiushuitian opened this issue · comments

I mean original function like this:

attributedString.setAttributes([NSFontAttributeName: UIFont.boldSystemFont(ofSize: 18)], range: dontRange)

You can set range by calling the method setAttributes(attributes: TextAttributes , range:)

let baseString = "Don't use magic numbers."
let attributedString = NSMutableAttributedString(string: baseString, attributes: nil)

let dontRange = (attributedString.string as NSString).range(of: "Don't")

let attr = TextAttributes()
.font(UIFont.systemFont(ofSize: 10))
.foregroundColor(.white)

attributedString.setAttributes(attr, range: dontRange)

Thanks @kmohsin11 :)