Answers for "swift apply changes after a word in string"

0

swift apply changes after a word in string

let longString = "Lorem ipsum dolor. VeryLongWord ipsum foobar"
let longestWord = "VeryLongWord"

let longestWordRange = (longString as NSString).rangeOfString(longestWord)

let attributedString = NSMutableAttributedString(string: longString, attributes: [NSFontAttributeName : UIFont.systemFontOfSize(20)])

attributedString.setAttributes([NSFontAttributeName : UIFont.boldSystemFontOfSize(20), NSForegroundColorAttributeName : UIColor.redColor()], range: longestWordRange)


label.attributedText = attributedString
Posted by: Guest on June-04-2020

Code answers related to "swift apply changes after a word in string"

Code answers related to "Swift"

Browse Popular Code Answers by Language