NSMutableAttributedString *attString = [[NSMutableAttributedString alloc]
initWithString:@"Listen to the web"];
[attString addAttribute:NSUnderlineStyleAttributeName
value:[NSNumber numberWithInt:2] range:NSMakeRange(10, 7)];
label.attributedText = attString;
1210݄5༵ۚ
Slide 12
Slide 12 text
Available in UIKit
• UITextView
• UITextField
• UILabel
• UIButton
• UITableView
• UIPickerVIew
for example...
1210݄5༵ۚ
Slide 13
Slide 13 text
Available Attributes
• Font
• Text color
• Paragraph style
• Text background color
• Ligature, kerning, and baseline offset
• Underline and strike-through
• Stroke width and color
• Shadow
1210݄5༵ۚ
Slide 14
Slide 14 text
One more thing
A little bit advanced talk from now,
(and personal)
1210݄5༵ۚ
Slide 15
Slide 15 text
Can I use this for Syntax Highlighting on
UITextView?
1210݄5༵ۚ
Slide 16
Slide 16 text
On my web speaker app,
I wanna highlight the text being
spoken in real time.
(Without using CoreText.)
This is UITextView.
1210݄5༵ۚ
Slide 17
Slide 17 text
Something like this.
With NSAttributedString.
1210݄5༵ۚ
Slide 18
Slide 18 text
Unfortunately,
we need to reset UITextView
every time setting a new attributedString.
textView.attributedText = attString
So, it can be too SLOW for long text.
(It must be ok for short text)
1210݄5༵ۚ
Slide 19
Slide 19 text
Possible
textView replaceRange:(UITextRange *) withText:(NSString *)
Not Possible
textView replaceRange:(UITextRange *) withText:
(NSAttributedString *)
1210݄5༵ۚ
Slide 20
Slide 20 text
1210݄5༵ۚ
Slide 21
Slide 21 text
Anyway,
it doesn’t matter for
most of developers.
NSAttributedString for iOS is really nice!
1210݄5༵ۚ
Slide 22
Slide 22 text
Thank you
If you are interested, check out the session of WWDC2012 to find out more.
“Session 222 - Introduction to Attributed Strings for iOS”
1210݄5༵ۚ