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

IdentifiableUIKit

Avatar for gaussbeam gaussbeam
November 25, 2016

 IdentifiableUIKit

2016.11.25 shinagawa.swift

Avatar for gaussbeam

gaussbeam

November 25, 2016
Tweet

More Decks by gaussbeam

Other Decks in Technology

Transcript

  1. Interface Builderʹ΋ͬͱؤுͬͯ΄͍͜͠ͱ ͦͷ̍ ɹؙ֯ʹ͍ͨ͠ ɹυϩοϓγϟυ΢͚͍ͭͨ ɹϘʔμʔ͚͍ͭͨ WJFXMBZFSDPSOFS3BEJVT WJFXMBZFSCPSEFS8JEUI WJFXMBZFSCPSEFS$PMPS 6*$PMPSXIJUF$PMPS

    $($PMPS WJFXMBZFSTIBEPX0QBDJUZ WJFXMBZFSTIBEPX0⒎TFU $(4J[F XJEUI IFJHIU  WJFXMBZFSTIBEPX$PMPS 6*$PMPSCMBDL$PMPS $($PMPS WJFXMBZFSTIBEPX3BEJVT TIBEPX3BEJVT
  2. @IBDesignable class IdentifiableView: UIView { @IBInspectable var … ɹoverride drawRect(rect:

    CGRect) { ɹɹ… ɹ} } Interface Builder্Ͱଈ࣌൓ө →@IBDesignable, @IBInspectableͰ࣮ݱ
  3. @IBDesignable class IdentifiableView: UIView { @IBInspectable var backgroundColorKey: String =

    “" ɹ… ɹoverride drawRect(rect: CGRect) { ɹɹview.backgroundColor = colorStyle.getColor(colorKey: self.backgroundColorKey) ɹɹ… ɹ} } Interface Builder্Ͱଈ࣌൓ө + ϏϡʔͷελΠϧΛIDͰࢦఆ →drawRect()಺Ͱͷ৭΍ελΠϧऔಘΛIDʹΑΓߦ͏
  4. protocol ColorIdentifiable { var colorStyle: ColorStyleType.Type? { get } }

    protocol ColorStyleType { static var colorDic: [String: UIColor] { get } } @IBDesignable class IdentifiableView: UIView, ColorIdentifiable { … } ϏϡʔͷελΠϧΛIDͰࢦఆ →Ϗϡʔʹ(ColorStyleTypeͷม਺Λ௨ͯ͡)ελΠϧͷࣙॻΛ࣋ͨͤΔ
  5. class MyColorStyle: NSObject, ColorStyleType { static var colorDic: [String: UIColor]

    = [ “C01": UIColor.redColor(), … ] } ελΠϧ͸ࣗ༝ʹఆٛͰ͖Δ →IdentifiableViewΛܧঝͨ͠Ϗϡʔʹඥ෇͚ class MyView: IdentifiableView { override var colorStyle: ColorStyleType.Type? { return MyColorStyle.self } } →ColorStyleTypeʹద߹ͨ͠ClassΛఆٛ͠
  6. IdentifiableUIKit •ϏϡʔͷελΠϧΛIDͰࢦఆ •Interface Builder্(=Ϗϧυෆཁ) Ͱଈ࣌൓ө •ελΠϧ͸ࣗ༝ʹఆٛͰ͖Δ Sorry, it’s for Swift

    2.2… • (view.layerͰখࡉ޻͍ͯ͠ΔͨΊɺෳࡶͳϏϡʔͰ͸ॏ͘ͳΔ͔΋…) https://github.com/gaussbeam/IdentifiableUIKit