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.6k
iOS6のNSAttributedString
NSAttributedStringで簡単にテキストをカスタマイズして、UITextViewにぶち込んだりできるよ。
Non Umemoto
February 23, 2013
Tweet
Share
More Decks by Non Umemoto
See All by Non Umemoto
Helpshiftについて - フィードバック駆動開発
umekun123
2
700
5分でわかるiOS7のiAdとTips
umekun123
0
5.9k
NSAttributedString for iOS
umekun123
0
190
Other Decks in Technology
See All in Technology
オーナーシップを持つ領域を明確にする
konifar
11
2.5k
4年前、あるじゃん老害エンジニアLT合戦に登壇、米国西海岸コンピュータ歴史博物館体験記の続編
toshi_atsumi
0
200
Discord とビルダー&チャットボットの使い方 / How to use Discord and Builder & Chatbots
ks91
PRO
0
130
プロデザ! BY リクルート vol.18_リクルートのリサーチ実践組織「リサーチブーストコミュニティ」
recruitengineers
PRO
3
240
ユーザーストーリーのレビューを自動化したみたの
bun913
1
320
**強い**エンジニアのなり方 - フィードバックサイクルを勝ち取る / grow one day each day
soudai
61
18k
シン・Kafka / shin-kafka
oracle4engineer
PRO
7
2.7k
ここが嬉しいABAC ここが辛いよABAC #再解説+補足編
masahirokawahara
0
220
"好き"との生活/Regularly update profile with GitHub Actions
judeeeee
0
150
Vertex AI を中心に 生成AIのアップデートを共有します
kaz1437
0
140
社内勉強会運営のコツ
senoo
6
1.1k
疲弊しない!AWSセキュリティ統制の考え方 #devio_osakaday1
masahirokawahara
6
5.9k
Featured
See All Featured
Principles of Awesome APIs and How to Build Them.
keavy
120
16k
Designing with Data
zakiwarfel
95
4.8k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
501
140k
What's new in Ruby 2.0
geeforr
337
31k
The Invisible Side of Design
smashingmag
294
49k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
658
120k
Pencils Down: Stop Designing & Start Developing
hursman
117
11k
In The Pink: A Labor of Love
frogandcode
138
21k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
220
21k
Build The Right Thing And Hit Your Dates
maggiecrowley
23
2k
Why You Should Never Use an ORM
jnunemaker
PRO
50
8.6k
Optimising Largest Contentful Paint
csswizardry
7
2.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༵