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
iOS6のNSAttributedString
Search
Non Umemoto
February 23, 2013
Technology
2
4.7k
iOS6のNSAttributedString
NSAttributedStringで簡単にテキストをカスタマイズして、UITextViewにぶち込んだりできるよ。
Non Umemoto
February 23, 2013
Tweet
Share
More Decks by Non Umemoto
See All by Non Umemoto
Helpshiftについて - フィードバック駆動開発
umekun123
2
710
5分でわかるiOS7のiAdとTips
umekun123
0
6k
NSAttributedString for iOS
umekun123
0
210
Other Decks in Technology
See All in Technology
データ活用促進のためのデータ分析基盤の進化
takumakouno
2
400
End of Barrel Files: New Modularization Techniques with Sheriff
rainerhahnekamp
0
280
Exadata Database Service on Cloud@Customer セキュリティ、ネットワーク、および管理について
oracle4engineer
PRO
0
1.1k
3次元点群データ「VIRTUAL SHIZUOKA』のオープンデータ化による恩恵と協働の未来/FOSS4G Japan 2024
kazz24s
0
130
全社横断データ活用推進のコツと その負債とのつき合い方
masatoshi0205
0
170
信頼性に挑む中で拡張できる・得られる1人のスキルセットとは?
ken5scal
1
400
音声×Copilot オンコパの世界
kasada
1
110
LINEヤフー株式会社における音声言語情報処理AI研究開発@SP/SLP研究会 2024.10.22
lycorptech_jp
PRO
2
280
신뢰할 수 있는 AI 검색 엔진을 만들기 위한 Liner의 여정
huffon
0
540
[FOSS4G 2024 Japan LT] LLMを使ってGISデータ解析を自動化したい!
nssv
1
170
RustとWebAssemblyを使って高速な画像処理をWebアプリで実行しよう
rebonire626
0
100
ライブラリでしかお目にかかれない珍しい実装
mikanichinose
2
330
Featured
See All Featured
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
126
18k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
15
2k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
42
9.2k
Faster Mobile Websites
deanohume
305
30k
Adopting Sorbet at Scale
ufuk
73
9.1k
Art, The Web, and Tiny UX
lynnandtonic
297
20k
Teambox: Starting and Learning
jrom
133
8.8k
Imperfection Machines: The Place of Print at Facebook
scottboms
264
13k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
364
24k
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.5k
Intergalactic Javascript Robots from Outer Space
tanoku
268
27k
Transcript
Attributed Strings in iOS6 132݄24༵
ࣗݾհ • കຊ ஆ @umekun123 • Lisgo (WebهࣄΛ͋ͱͰฉ͘ΞϓϦ) • umenon.com
(ΞϓϦ։ൃฃಆه) 132݄24༵
iOS5 NSStringͷࡉ͔͍ૢ࡞͕Ͱ͖Μʂ 132݄24༵
iOS5 NSString in UILabel 132݄24༵
UILabel *label = [[UILabel alloc] init]; ~~ লུ ~~ label.text
= @"Listen to the web"; 132݄24༵
iOS6 NSAttributedStringͰϞςϞςʂ CoreTextΘͳ͍ͯ͘Ζ͍ΖͰ͖ͪΌ͏ 132݄24༵
iOS6 NSAttributedString NSKernAttributeName 132݄24༵
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; 132݄24༵
iOS6 NSAttributedString NSForegroundColorAttributeName 132݄24༵
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; 132݄24༵
iOS6 NSAttributedString NSUnderlineStyleAttributeName 132݄24༵
NSMutableAttributedString *attString = [[NSMutableAttributedString alloc] initWithString:@"Listen to the web"]; [attString
addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInt:2] range:NSMakeRange(10, 7)]; label.attributedText = attString; 132݄24༵
UIKitͰ͑·͢ • UITextView • UITextField • UILabel • UIButton •
UITableView • UIPickerVIew ྫ͑... 132݄24༵
AttributesͰ͍͡ΕΔࣄ • ϑΥϯτͷछྨ • ςΩετͷ৭ • ύϥάϥϑͷελΠϧ (ߴ͞ઃఆʹόά͋Δ) • ςΩετഎܠͷ৭
• จࣈִؒͷௐͱ͔ • Լઢɺதઢ͚ͭͨΓ • Ө͚ͭͨΓ ͦͷଞʹ͍Ζ͍Ζ (ৄ͘͠υΩϡϝϯτͰ) 132݄24༵
ຯͳ༻ྫ NSMutableParagraphStyleͰɺೋߦͷ هࣄλΠτϧͷ্ԼͷִؒΛͭΊͯ ͍·͢ɻ 132݄24༵
͓·͚ NSAttributedStringsͰ೦ͩͬͨ͜ͱ 132݄24༵
UITextViewͰϦΞϧλΠϜϋΠϥΠτ ͍ͨͬ͢͠ʂ 132݄24༵
ͷLisgoͱ͍͏ಡΈ্͛ΞϓϦ ͰɺಡΈ্͛தͷςΩετΛ UITextView্ͰϦΞϧλΠϜϋΠϥ Πτʹઓɻ 132݄24༵
NSAttributedStringͰϋΠϥΠτ ͢Δͱ͜Μͳײ͡ɻ ͓͓ɺ͜ΕͰ͖ͦ͏ɻ 132݄24༵
೦ͳ͓Βͤɻ ৽͍͠attributedStringΛηοτ͢Δͨͼʹ UITextviewΛϦηοτ͠ͳ͍ͱ͍͚ͳ͍ɻ textView.attributedText = attString ͳͷͰɺ͍จষͷதͰɺϋΠϥΠτՕॴ͕ ΆΜΆΜมΘΔͱॏ͘ͳͬͯΨΫΨΫɻ ϦΞϧλΠϜʹϋΠϥΠτՕॴม͑ͳ͍ͳΒϊʔϓϩϒϨϜͰ͢ɻ ※LisgoͰ݁ہUITextRange͔ΒCGRectऔͬͯViewష͚࣮ͯݱ͠·ͨ͠ɻ
132݄24༵
͜ΕͰ͖Δͷʹ textView replaceRange:(UITextRange *) withText:(NSString *) ͜ΕͰ͖ͳ͍(ྦ) textView replaceRange:(UITextRange *)
withText: (NSAttributedString *) 132݄24༵
132݄24༵
ࡉ͔͍ෆຬ͋Δ͚Ͳɺجຊతʹ NSAttributedsStringsศརʂ ૉΒ͖͠iOS6ͷੈքɻ 132݄24༵
͋Γ͕ͱ͏͍͟͝·ͨ͠ WWDC2012ͷηογϣϯݟΕͬͱࡉ͔͍෦͕Θ͔Δʂ “Session 222 - Introduction to Attributed Strings for
iOS” 132݄24༵