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

フォントの基本とUIFont/UIFontDescriptor

satoshin21
January 14, 2017

 フォントの基本とUIFont/UIFontDescriptor

デザイナーとのコミュニケーションに必須なフォントの基本と
iOSの開発に用いられるUIFontと更に柔軟にフォントを扱えるUIFontDescriptorについて #potatotips36

satoshin21

January 14, 2017
Tweet

More Decks by satoshin21

Other Decks in Programming

Transcript

  1. satoshin21 SatoshiN21 ௕ࡔ ޛࢤ (Nagasaka Satoshi) - iOS Engineer of

    pairs Div. eureka, Inc. - Swift, Objective-C, Java(Android), Apple Script
  2. UIFont ‣ 6*'POU͕͍࣋ͬͯΔ৘ใ w /BNF GPOU/BNF GBNJMZ/BNF  w QPJOU4J[F

    w )FJHIUܥ MJOF)FJHIU MFBEJOH DBQ)FJHIU  w CBTFMJOFܥ
  3. baseline CBTFMJOF YIFJHIU DBQTIFJHIU "TDFOEFS %FTDFOEFS ‣ CBTFMJOFΛى఺ʹͯ͠ԤจϑΥϯτ͸ϨΠΞ΢τ͞ΕΔ ‣ BTDFOEFS

    w CBTFMJOF͔Β্෦ͷڑ཭ ‣ EFTDFOEFS w CBTFMJOF͔ΒԼ෦ͷڑ཭ ෛ਺  ‣ MFBEJOH w GPOUͷ࣋ͭߦؒ஋ w MFBEJOHͷͳ͍ϑΥϯτ΋ γεςϜϑΥϯτͳͲ
  4. // San Francisco(.SFUIText) let font = UIFont.systemFont(ofSize: 12) let height

    = abs(font.descender) + font.ascender + font.leading font.lineHeight == height // true font.lineHeight
  5. AutoLayout தԝἧ͑ minLabel.leftAnchor.constraint(equalTo: view.leftAnchor, constant: 10).isActive = true minLabel.rightAnchor.constraint(equalTo: largeLabel.leftAnchor,

    constant: -12).isActive = true // Y軸を揃える minLabel.centerYAnchor .constraint(equalTo: largeLabel.centerYAnchor).isActive = true
  6. UIFontDescriptorCascadeListAttribute let fontDescriptor = UIFontDescriptor(fontAttributes: [UIFontDescriptorNameAttribute: ".SFUIDisplay"]) let japaneseFont =

    UIFontDescriptor(fontAttributes: [UIFontDescriptorNameAttribute: "HiraMinProN-W3"]) // カスケードフォントを配列で指定 let mixedFontDescriptor = fontDescriptor.addingAttributes([UIFontDescriptorCascadeListAttribute: [japaneseFont]]) label.font = UIFont(descriptor: mixedFontDescriptor, size: 75)
  7. UIFontDescriptorMatrixAttribute let scale = CGAffineTransform(scaleX: 1.0, y: 2.0) let fontDescriptor

    = UIFontDescriptor(name: ".SFUIDisplay", matrix: scale) label.font = UIFont(descriptor: fontDescriptor, size: 75)
  8. UIFontDescriptorMatrixAttribute let rotate = CGAffineTransform(rotationAngle: CGFloat(M_PI * 15.0 / 180.0))

    let fontDescriptor = UIFontDescriptor(name: ".SFUIDisplay", matrix: rotate) label2.font = UIFont(descriptor: fontDescriptor, size: 75)