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
Non Umemoto
October 04, 2012
Programming
0
230
NSAttributedString for iOS
NSAttributedString for iOS in iOS Meetup Tokyo
Non Umemoto
October 04, 2012
Tweet
Share
More Decks by Non Umemoto
See All by Non Umemoto
Helpshiftについて - フィードバック駆動開発
umekun123
2
740
5分でわかるiOS7のiAdとTips
umekun123
0
6k
iOS6のNSAttributedString
umekun123
2
4.8k
Other Decks in Programming
See All in Programming
Amazon Q CLI開発で学んだAIコーディングツールの使い方
licux
3
150
DMMを支える決済基盤の技術的負債にどう立ち向かうか / Addressing Technical Debt in Payment Infrastructure
yoshiyoshifujii
5
710
リッチエディターを安全に開発・運用するために
unachang113
1
340
MCP連携で加速するAI駆動開発/mcp integration accelerates ai-driven-development
bpstudy
0
240
Vibe Codingの幻想を超えて-生成AIを現場で使えるようにするまでの泥臭い話.ai
fumiyakume
21
9.8k
AIコーディングエージェント全社導入とセキュリティ対策
hikaruegashira
15
9.1k
PHPカンファレンス関西2025 基調講演
sugimotokei
6
1.1k
バイブコーディングの正体——AIエージェントはソフトウェア開発を変えるか?
stakaya
5
580
なぜあなたのオブザーバビリティ導入は頓挫するのか
ryota_hnk
4
550
プロダクトという一杯を作る - プロダクトチームが味の責任を持つまでの煮込み奮闘記
hiliteeternal
0
330
商品比較サービス「マイベスト」における パーソナライズレコメンドの第一歩
ucchiii43
0
240
JetBrainsのAI機能の紹介 #jjug
yusuke
0
160
Featured
See All Featured
Music & Morning Musume
bryan
46
6.7k
Designing Experiences People Love
moore
142
24k
Writing Fast Ruby
sferik
628
62k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
667
120k
Code Reviewing Like a Champion
maltzj
524
40k
Build The Right Thing And Hit Your Dates
maggiecrowley
37
2.8k
Visualization
eitanlees
146
16k
Java REST API Framework Comparison - PWX 2021
mraible
31
8.7k
Code Review Best Practice
trishagee
69
19k
Imperfection Machines: The Place of Print at Facebook
scottboms
267
13k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
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༵ۚ