Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
NSAttributedString for iOS
Search
Non Umemoto
October 04, 2012
Programming
250
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
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
750
5分でわかるiOS7のiAdとTips
umekun123
0
6.1k
iOS6のNSAttributedString
umekun123
2
4.9k
Other Decks in Programming
See All in Programming
Modernizing iOS Apps
seyfoyun
0
150
TS 7.0 で baseUrl が使えなくなった今、パスエイリアスをどうするか
bicstone
2
560
作れるエンジニアから、価値を届けるエンジニアへ
ryunakayama
1
240
Vapor Mode でアクセシビリティは 壊れないか検証した話
fuqda
1
330
TanStack Vue Query と Pinia Colada から学ぶ非同期状態の型設計
aoshi
0
630
社内AIエージェント「Askワンバン」における コストチューニングの取り組み
t0yohei
0
160
Kawaiicon: Kubernetes, it's no longer cool, but let's secure it anyway!
barnbarn
0
130
우리의 Nitro Modules는 당신의 Turbo Modules보다 아름답다
l2hyunwoo
0
260
Rails初心者がパスキーを実装してみて大変だったこと
ktombow
0
160
Railsバージョンを4倍にした話
optim
0
960
Railsのためのパスキー実践入門 〜マルチテナントSaaSでの意思決定〜
utakaha
4
3.6k
GraphQL の onError と Nullability のこれから
quramy
0
210
Featured
See All Featured
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.8k
More Than Pixels: Becoming A User Experience Designer
marktimemedia
3
620
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
1
560
Reflections from 52 weeks, 52 projects
jeffersonlam
356
22k
Believing is Seeing
oripsolob
1
270
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.8k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
35
2.9k
The World Runs on Bad Software
bkeepers
PRO
72
12k
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
560
Un-Boring Meetings
codingconduct
0
490
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
570
jQuery: Nuts, Bolts and Bling
dougneiner
66
8.7k
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༵ۚ