Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
NSAttributedString for iOS
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Non Umemoto
October 04, 2012
Programming
240
0
Share
NSAttributedString for iOS
NSAttributedString for iOS in iOS Meetup Tokyo
Non Umemoto
October 04, 2012
More Decks by Non Umemoto
See All by Non Umemoto
Helpshiftについて - フィードバック駆動開発
umekun123
2
740
5分でわかるiOS7のiAdとTips
umekun123
0
6.1k
iOS6のNSAttributedString
umekun123
2
4.9k
Other Decks in Programming
See All in Programming
YJITとZJITにはイカなる違いがあるのか?
nakiym
0
220
GNU Makeの使い方 / How to use GNU Make
kaityo256
PRO
16
5.6k
Alternatives to JPA 2026
debop
0
110
Coding as Prompting Since 2025
ragingwind
0
830
mruby on C#: From VM Implementation to Game Scripting (RubyKaigi 2026)
hadashia
2
340
実用!Hono RPC2026
yodaka
2
210
AIベース静的検査器の偽陽性率を抑える工夫3選
orgachem
PRO
3
190
t *testing.T は どこからやってくるの?
otakakot
1
600
Google Nest CamとApple Vision frameworkと猫🐈🐈⬛ / onishi50
yutailang0119
0
110
瑠璃の宝石に学ぶ技術の声の聴き方 / 【劇場版】アニメから得た学びを発表会2026 #エンジニアニメ
mazrean
0
250
AIエージェントで業務改善してみた
taku271
0
520
アーキテクチャモダナイゼーションとは何か
nwiizo
17
5.1k
Featured
See All Featured
Fashionably flexible responsive web design (full day workshop)
malarkey
408
66k
4 Signs Your Business is Dying
shpigford
187
22k
The SEO Collaboration Effect
kristinabergwall1
0
420
Tips & Tricks on How to Get Your First Job In Tech
honzajavorek
1
490
Joys of Absence: A Defence of Solitary Play
codingconduct
1
350
Building a Modern Day E-commerce SEO Strategy
aleyda
45
9k
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
1
190
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.2k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.1k
Avoiding the “Bad Training, Faster” Trap in the Age of AI
tmiket
0
130
エンジニアに許された特別な時間の終わり
watany
106
240k
Navigating Team Friction
lara
192
16k
Transcript
Attributed Strings in iOS6 Non Umemoto @umekun123 1210݄5༵ۚ
iOS5 You have limited power with NSString 1210݄5༵ۚ
iOS5 NSString in UILabel 1210݄5༵ۚ
UILabel *label = [[UILabel alloc] init]; ~~ some codes for
label ~~ label.text = @"Listen to the web"; 1210݄5༵ۚ
iOS6 You have more power with NSAttributedString There are a
lot of hassles for using CoreText, right? 1210݄5༵ۚ
iOS6 NSAttributedString NSKernAttributeName 1210݄5༵ۚ
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; 1210݄5༵ۚ
iOS6 NSAttributedString NSForegroundColorAttributeName 1210݄5༵ۚ
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; 1210݄5༵ۚ
iOS6 NSAttributedString NSUnderlineStyleAttributeName 1210݄5༵ۚ
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༵ۚ
Available in UIKit • UITextView • UITextField • UILabel •
UIButton • UITableView • UIPickerVIew for example... 1210݄5༵ۚ
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༵ۚ
One more thing A little bit advanced talk from now,
(and personal) 1210݄5༵ۚ
Can I use this for Syntax Highlighting on UITextView? 1210݄5༵ۚ
On my web speaker app, I wanna highlight the text
being spoken in real time. (Without using CoreText.) This is UITextView. 1210݄5༵ۚ
Something like this. With NSAttributedString. 1210݄5༵ۚ
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༵ۚ
Possible textView replaceRange:(UITextRange *) withText:(NSString *) Not Possible textView replaceRange:(UITextRange
*) withText: (NSAttributedString *) 1210݄5༵ۚ
1210݄5༵ۚ
Anyway, it doesn’t matter for most of developers. NSAttributedString for
iOS is really nice! 1210݄5༵ۚ
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༵ۚ