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
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Non Umemoto
October 04, 2012
Programming
240
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
740
5分でわかるiOS7のiAdとTips
umekun123
0
6.1k
iOS6のNSAttributedString
umekun123
2
4.9k
Other Decks in Programming
See All in Programming
IBM Bobを活用したレガシーアプリの最新化
oniak3ibm
PRO
1
210
JavaDoc 再入門
nagise
1
380
例外の正しい扱い方 そのエラー try-catchして大丈夫?
jinwatanabe
0
270
Go1.27で導入されるジェネリクスメソッドでできること
mackee
0
170
Claspは野良GASの夢をみるか
takter00
0
200
「AIで開発し、AIを届ける」をEvalでつなぐ 〜AIネイティブに始めるプロダクト開発の実践〜 / Connecting "Develop with AI, deliver AI" with Eval
rkaga
4
5.3k
dRuby over BLE
makicamel
2
390
さぁV100、メモリをお食べ・・・
nilpe
0
150
AI 輔助遺留系統現代化的經驗分享
jame2408
1
960
Dataformのリポジトリを立ち上げるときにまずやること / dataform-day0-2026
snhryt
0
180
AIを活用したE2Eテスト実装効率化のあゆみ / ebisu-mobile-14-kotetu
kotetuco
0
130
代数的データ型って何が嬉しいの? #frontend_phpcon_do
kajitack
8
3.8k
Featured
See All Featured
Everyday Curiosity
cassininazir
0
230
A designer walks into a library…
pauljervisheath
211
24k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
2k
Building Applications with DynamoDB
mza
96
7.1k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.2k
WENDY [Excerpt]
tessaabrams
11
38k
Ethics towards AI in product and experience design
skipperchong
2
310
The browser strikes back
jonoalderson
0
1.3k
Prompt Engineering for Job Search
mfonobong
0
350
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
230
23k
jQuery: Nuts, Bolts and Bling
dougneiner
66
8.5k
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
62
54k
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༵ۚ