Slide 1

Slide 1 text

Attributed Strings in iOS6 Non Umemoto @umekun123 12೥10݄5೔༵ۚ೔

Slide 2

Slide 2 text

iOS5 You have limited power with NSString 12೥10݄5೔༵ۚ೔

Slide 3

Slide 3 text

iOS5 NSString in UILabel 12೥10݄5೔༵ۚ೔

Slide 4

Slide 4 text

UILabel *label = [[UILabel alloc] init]; ~~ some codes for label ~~ label.text = @"Listen to the web"; 12೥10݄5೔༵ۚ೔

Slide 5

Slide 5 text

iOS6 You have more power with NSAttributedString There are a lot of hassles for using CoreText, right? 12೥10݄5೔༵ۚ೔

Slide 6

Slide 6 text

iOS6 NSAttributedString NSKernAttributeName 12೥10݄5೔༵ۚ೔

Slide 7

Slide 7 text

UILabel *label = [[UILabel alloc] init]; ~~ some codes for label ~~ NSMutableAttributedString *attString = [[NSMutableAttributedString alloc] initWithString:@"Listen to the web"]; NSInteger stringLength = [attString length]; [attString addAttribute:NSKernAttributeName value:@5 range:NSMakeRange(0, stringLength)]; label.attributedText = attString; 12೥10݄5೔༵ۚ೔

Slide 8

Slide 8 text

iOS6 NSAttributedString NSForegroundColorAttributeName 12೥10݄5೔༵ۚ೔

Slide 9

Slide 9 text

NSMutableAttributedString *attString = [[NSMutableAttributedString alloc] initWithString:@"Listen to the web"]; UIColor *_red = [UIColor redColor]; [attString addAttribute:NSForegroundColorAttributeName value:_red range:NSMakeRange(0, 6)]; label.attributedText = attString; 12೥10݄5೔༵ۚ೔

Slide 10

Slide 10 text

iOS6 NSAttributedString NSUnderlineStyleAttributeName 12೥10݄5೔༵ۚ೔

Slide 11

Slide 11 text

NSMutableAttributedString *attString = [[NSMutableAttributedString alloc] initWithString:@"Listen to the web"]; [attString addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInt:2] range:NSMakeRange(10, 7)]; label.attributedText = attString; 12೥10݄5೔༵ۚ೔

Slide 12

Slide 12 text

Available in UIKit • UITextView • UITextField • UILabel • UIButton • UITableView • UIPickerVIew for example... 12೥10݄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 12೥10݄5೔༵ۚ೔

Slide 14

Slide 14 text

One more thing A little bit advanced talk from now, (and personal) 12೥10݄5೔༵ۚ೔

Slide 15

Slide 15 text

Can I use this for Syntax Highlighting on UITextView? 12೥10݄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. 12೥10݄5೔༵ۚ೔

Slide 17

Slide 17 text

Something like this. With NSAttributedString. 12೥10݄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) 12೥10݄5೔༵ۚ೔

Slide 19

Slide 19 text

Possible textView replaceRange:(UITextRange *) withText:(NSString *) Not Possible textView replaceRange:(UITextRange *) withText: (NSAttributedString *) 12೥10݄5೔༵ۚ೔

Slide 20

Slide 20 text

12೥10݄5೔༵ۚ೔

Slide 21

Slide 21 text

Anyway, it doesn’t matter for most of developers. NSAttributedString for iOS is really nice! 12೥10݄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” 12೥10݄5೔༵ۚ೔