Instead of creating a local NSMutableAttributedString
and adding attributes one by one, we can always create multiple attributes in one single line (using NSDictionary symbols - @ { } ) to a specific UILabel including the actual text.
Objective C:
[someUILabel setAttributedText:
[[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@", [someObject stringProperty]]
attributes:@{NSUnderlineStyleAttributeName:@(NSUnderlineStyleThick),
NSUnderlineColorAttributeName:[[UIColor alloc] initWithRed:0.953f green:0.424f blue:0.416f alpha:1.00f]}]];
In the above example we have set an underline which is also bold - total 2 attributes.
Swift:
self.someUIButton.setAttributedTitle(NSAttributedString(string: "UIButtonStringTitle", attributes: [NSUnderlineStyleAttributeName : 1]), forState: .Normal)