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
OS 標準のデザインシステムを超えて - より柔軟な Flutter テーマ管理 | FlutterKaigi 2024
ronnnnn
1
330
SRE×AIOpsを始めよう!GuardDutyによるお手軽脅威検出
amixedcolor
1
220
Storybook との上手な向き合い方を考える
re_taro
5
2.1k
【平成レトロ】へぇボタンハック👨🔧
vanchan2625
0
110
TanStack Routerに移行するのかい しないのかい、どっちなんだい! / Are you going to migrate to TanStack Router or not? Which one is it?
kaminashi
0
640
初心者向けAWS Securityの勉強会mini Security-JAWSを9ヶ月ぐらい実施してきての近況
cmusudakeisuke
0
140
SDNという名のデータプレーンプログラミングの歴史
ebiken
PRO
2
180
【Pycon mini 東海 2024】Google Colaboratoryで試すVLM
kazuhitotakahashi
2
590
Amplify Gen2 Deep Dive / バックエンドの型をいかにしてフロントエンドへ伝えるか #TSKaigi #TSKaigiKansai #AWSAmplifyJP
tacck
PRO
0
410
強いチームと開発生産性
onk
PRO
36
12k
テストコード品質を高めるためにMutation Testingライブラリ・Strykerを実戦導入してみた話
ysknsid25
7
2.7k
FlutterアプリにおけるSLI/SLOを用いたユーザー体験の可視化と計測基盤構築
ostk0069
0
150
Featured
See All Featured
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
10 Git Anti Patterns You Should be Aware of
lemiorhan
655
59k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
4
380
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
730
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
16
2.1k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
111
49k
How to Think Like a Performance Engineer
csswizardry
20
1.1k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
329
21k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
229
52k
Embracing the Ebb and Flow
colly
84
4.5k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
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༵