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.8k
iOS6のNSAttributedString
NSAttributedStringで簡単にテキストをカスタマイズして、UITextViewにぶち込んだりできるよ。
Non Umemoto
February 23, 2013
Tweet
Share
More Decks by Non Umemoto
See All by Non Umemoto
Helpshiftについて - フィードバック駆動開発
umekun123
2
720
5分でわかるiOS7のiAdとTips
umekun123
0
6k
NSAttributedString for iOS
umekun123
0
220
Other Decks in Technology
See All in Technology
信頼されるためにやったこと、 やらなかったこと。/What we did to be trusted, What we did not do.
bitkey
PRO
0
1.6k
「完全に理解したTalk」完全に理解した
segavvy
1
270
OPENLOGI Company Profile for engineer
hr01
1
17k
DevFest 2024 Incheon / Songdo - Compose UI 조합 심화
wisemuji
0
250
20241218_マルチアカウント環境におけるIAM_Access_Analyzerによる権限管理.pdf
nrinetcom
PRO
3
150
.NET 最新アップデート ~ AI とクラウド時代のアプリモダナイゼーション
chack411
0
150
ネットワーク可視化の世界
likr
7
5.7k
ZOZOTOWN の推薦における KPI モニタリング/KPI monitoring for ZOZOTOWN recommendations
rayuron
1
900
.NET 9 のパフォーマンス改善
nenonaninu
0
2.2k
AI×医用画像の現状と可能性_2024年版/AI×medical_imaging_in_japan_2024
tdys13
0
1.2k
生成AIによるテスト設計支援プロセスの構築とプロセス内のボトルネック解消の取り組み / 20241220 Suguru Ishii
shift_evolve
0
180
PHP ユーザのための OpenTelemetry 入門 / phpcon2024-opentelemetry
shin1x1
3
1.6k
Featured
See All Featured
Keith and Marios Guide to Fast Websites
keithpitt
410
22k
Measuring & Analyzing Core Web Vitals
bluesmoon
5
190
Designing Experiences People Love
moore
139
23k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
Making Projects Easy
brettharned
116
6k
We Have a Design System, Now What?
morganepeng
51
7.3k
Testing 201, or: Great Expectations
jmmastey
41
7.2k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
28
4.4k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
330
21k
No one is an island. Learnings from fostering a developers community.
thoeni
19
3.1k
Site-Speed That Sticks
csswizardry
2
220
Optimising Largest Contentful Paint
csswizardry
33
3k
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༵