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
730
5分でわかるiOS7のiAdとTips
umekun123
0
6k
NSAttributedString for iOS
umekun123
0
220
Other Decks in Technology
See All in Technology
こんなデータマートは嫌だ。どんな? / waiwai-data-meetup-202504
shuntak
6
1.8k
SDカードフォレンジック
su3158
1
550
Ops-JAWS_Organizations小ネタ3選.pdf
chunkof
2
120
アジャイル脅威モデリング#1(脅威モデリングナイト#8)
masakane55
3
180
LLM as プロダクト開発のパワードスーツ
layerx
PRO
1
220
Beyond {shiny}: The Future of Mobile Apps with R
colinfay
1
390
MCPを活用した検索システムの作り方/How to implement search systems with MCP #catalks
quiver
11
5.6k
ソフトウェア開発現代史: "LeanとDevOpsの科学"の「科学」とは何か? - DORA Report 10年の変遷を追って - #DevOpsDaysTokyo
takabow
0
360
大AI時代で輝くために今こそドメインにディープダイブしよう / Deep Dive into Domain in AI-Agent-Era
yuitosato
1
310
はてなの開発20年史と DevOpsの歩み / DevOpsDays Tokyo 2025 Keynote
daiksy
6
1.5k
MCP Documentation Server @AI Coding Meetup #1
yyoshiki41
2
2.6k
Рекомендации с нуля: как мы в Lamoda превратили главную страницу в ключевую точку входа для персонализированного шоппинга. Данил Комаров, Data Scientist, Lamoda Tech
lamodatech
0
590
Featured
See All Featured
Building an army of robots
kneath
304
45k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Large-scale JavaScript Application Architecture
addyosmani
512
110k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
41
2.2k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
19
1.1k
The World Runs on Bad Software
bkeepers
PRO
67
11k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
9
740
Understanding Cognitive Biases in Performance Measurement
bluesmoon
29
1.6k
Visualization
eitanlees
146
16k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
45
7.2k
Designing Experiences People Love
moore
141
24k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
26k
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༵