Tutorial by Examples

NSAttributedString (and its mutable sibling NSMutableAttributedString) allows you to create strings that are complex in their appearance to the user. A common application is to use this to display a string and adding custom kerning / letter-spacing. This would be achieved as follows (where label ...
Objective-C NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc] initWithString:@"Your String here"]; [attributeString addAttribute:NSStrikethroughStyleAttributeName value:@2 range:NSMakeRange(0, [attributeString length...
let someValue : String = "Something the user entered" let text = NSMutableAttributedString(string: "The value is: ") text.appendAttributedString(NSAttributedString(string: someValue, attributes: [NSFontAttributeName:UIFont.boldSystemFontOfSize(UIFont.systemFontSize())])) ...
Objective-C UIColor *color = [UIColor redColor]; NSString *textToFind = @"redword"; NSMutableAttributedString *attrsString = [[NSMutableAttributedString alloc] initWithAttributedString:yourLabel.attributedText]; // search for word occurrence NSRange range = [yourLabel.text rangeO...
Objective-C NSMutableAttributedString *mutAttString = @"string goes here"; NSRange range = NSMakeRange(0, mutAttString.length); [mutAttString setAttributes:@{} range:originalRange]; As per Apple Documentation we use, setAttributes and not addAttribute. Swift mutAttString.setAttribu...

Page 1 of 1