Upgrade to Pro — share decks privately, control downloads, hide ads and more …

TextKitから表現が広がる - iOSDC Japan 2018

Kohey
September 02, 2018

TextKitから表現が広がる - iOSDC Japan 2018

TextKitはiOS7から導入されたテキスト用のレンダリングエンジンです。これのおかげによって、低レベルのAPIを格闘することなく、開発でも難しいテキストでも比較的容易にレイアウトを描画できるようになっています。本トークでは、実際にデザイナーとあった話をもとに、文字列デザインをフォーカスして行きます。

Kohey

September 02, 2018
Tweet

Other Decks in Programming

Transcript

  1. Profile • Kohei Nishioka / Pref. Fukui • iOS Engineer

    @ iRidge Inc. • Swift, Objective-C, C++, Ocaml, 
 PHP, JavaScript … • Japanese / English • Github takumi314 • Twitter #paper_and_paper
  2. “This is what customers pay us for – to sweat

    all these details so it’s easy and pleasant for them to use our computers. We’re supposed to be really good at this. That doesn’t mean we don’t listen to customers, but it’s hard for them to tell you what they want when they’ve never seen anything remotely like it. Take desktop video editing. I never got one request from someone who wanted to edit movies on his computer. Yet now that people see it, they say, ‘Oh my God, that’s great!’ ”
  3. API groups w ςΩετΛදࣔ͢Δ w 6*5FYU7JFX w 6*5FYU'JFME w 6*-BCFM

    w ςΩετඳըΛ੍ޚ͢Δ w /4-BZPVU.BOBHFS w /45FYU$POUBJOFS w σΩετσʔλΛอ؅͢Δ w /4"UUSJCVUF4USJOH TextKitͷຊؙ
  4. API groups w ςΩετΛදࣔ͢Δ w 6*5FYU7JFX w 6*5FYU'JFME w 6*-BCFM

    w ςΩετඳըΛ੍ޚ͢Δ w /4-BZPVU.BOBHFS w /45FYU$POUBJOFS w σΩετσʔλΛอ؅͢Δ w /4"UUSJCVUF4USJOH View Controller Model
  5. NSTextStorage • TextKitͷModelʹ૬౰͢Δ • NSMutableAttributedStringͷSubclass (ΫϥεΫϥελ) • NSLayoutManagerͷมߋΛcharacters ΍ attributes

    ʹ
 ௨஌ͯ͠ඞཁͳΒ͹࠶දࣔΛଅ͢ • 1ͭຢ͸ෳ਺ͷNSLayoutManagerΛ࣋ͭ • ͲͷεϨου͔ΒͰ΋ΞΫηεՄೳ • ಉ࣌ʹෳ਺εϨου͔ΒͷΞΫηε͸ආ͚ͨํ͕ແ೉ https://developer.apple.com/documentation/uikit/nstextstorage
  6. Adding a Custom Font • αϙʔτ͍ͯ͠Δܗࣜ • True Type Font

    (*.ttf) • Open TypeFont (*.otf)
 • ະ֬ೝ • True Type Collection (*.ttc) ʁʁ
  7. I Love iOSDC textView.text = "I Love iOSDC" guard let

    originFont = UIFont(name: "Comic Sans MS", size: 24.0) else { return } let boldFontDescriper = originFont.fontDescriptor.withSymbolicTraits(.traitBold) let boldFont = UIFont(descriptor: boldFontDescriper!, size: (originFont.pointSize)) let newText = NSMutableAttributedString(string: textView.text) newText.addAttribute(.font, value: boldFont, range: NSRange(location: 1, length: 5)) textView.attributedText = newText
  8. I Love iOSDC textView.text = "I Love iOSDC" guard let

    originFont = UIFont(name: "Comic Sans MS", size: 24.0) else { return } let boldFontDescriper = originFont.fontDescriptor.withSymbolicTraits(.traitBold) let boldFont = UIFont(descriptor: boldFontDescriper!, size: (originFont.pointSize)) let newText = NSMutableAttributedString(string: textView.text) newText.addAttribute(.font, value: boldFont, range: NSRange(location: 1, length: 5)) textView.attributedText = newText I Love iOSDC
  9. textView.text = "I Love iOSDC" guard let originFont = UIFont(name:

    "Comic Sans MS", size: 24.0) else { return } let boldFontDescriper = originFont.fontDescriptor.withSymbolicTraits(.traitBold) let boldFont = UIFont(descriptor: boldFontDescriper!, size: (originFont.pointSize)) let newText = NSMutableAttributedString(string: textView.text) newText.addAttribute(.font, value: boldFont, range: NSRange(location: 1, length: 5)) textView.attributedText = newText
  10. I Love iOSDC Comic Sans MS 24-pt I Love iOSDC

    Arial Black 12-pt I Love iOSDC Helvetica 12-pt ద༻લ ॳظԽ ଐੑઃఆ
  11. Attributes with default values Baseline offset 0.0 Font Helvetica 12-pt

    Background color None (no background) Kern None (use font's default kerning) Ligature None (use font's standard ligatures) Link None Foreground color None (no background) Paragraph style defaultParagapghStyle
  12. I Love iOSDC textView.text = "I Love iOSDC" guard let

    originFont = UIFont(name: "Comic Sans MS", size: 24.0) else { return } let boldFontDescriper = originFont.fontDescriptor.withSymbolicTraits(.traitBold) let boldFont = UIFont(descriptor: boldFontDescriper!, size: (originFont.pointSize)) let newText = NSMutableAttributedString(attributedString: textView.attributedText) newText.addAttribute(.font, value: boldFont, range: NSRange(location: 1, length: 5)) textView.attributedText = newText ΠχγϟϥΠβʹଐੑ৘ใΛ༩͑Δ
  13. • Text Programming Guide for iOS - https:// developer.apple.com/library/archive/documentation/ StringsTextFonts/Conceptual/TextAndWebiPhoneOS/

    CustomTextProcessing/CustomTextProcessing.html • WWDC2018 “TextKit Best Practice” - session 221 • WWDC2013 “Introducing TextKit” - session 210 References