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
220
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
720
5分でわかるiOS7のiAdとTips
umekun123
0
6k
iOS6のNSAttributedString
umekun123
2
4.8k
Other Decks in Programming
See All in Programming
Ruby on cygwin 2025-02
fd0
0
140
AIの力でお手軽Chrome拡張機能作り
taiseiue
0
170
最近のVS Codeで気になるニュース 2025/01
74th
1
250
いりゃあせ、PHPカンファレンス名古屋2025 / Welcome to PHP Conference Nagoya 2025
ttskch
1
270
知られざるDMMデータエンジニアの生態 〜かつてツチノコと呼ばれし者〜
takaha4k
4
1.3k
プログラミング言語学習のススメ / why-do-i-learn-programming-language
yashi8484
0
120
SwiftUIで単方向アーキテクチャを導入して得られた成果
takuyaosawa
0
260
法律の脱レガシーに学ぶフロントエンド刷新
oguemon
5
730
Domain-Driven Transformation
hschwentner
2
1.9k
Grafana Cloudとソラカメ
devoc
0
140
Conform を推す - Advocating for Conform
mizoguchicoji
3
680
AWS Organizations で実現する、 マルチ AWS アカウントのルートユーザー管理からの脱却
atpons
0
130
Featured
See All Featured
Intergalactic Javascript Robots from Outer Space
tanoku
270
27k
KATA
mclloyd
29
14k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
7k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
20
2.4k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
3
310
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
3.7k
Building an army of robots
kneath
302
45k
Fashionably flexible responsive web design (full day workshop)
malarkey
406
66k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
160
15k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
6
540
Building Better People: How to give real-time feedback that sticks.
wjessup
366
19k
Designing for Performance
lara
604
68k
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༵ۚ