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

IdentifiableUIKit

39d636034f806b2bb51165a93774ab79?s=47 gaussbeam
November 25, 2016

 IdentifiableUIKit

2016.11.25 shinagawa.swift

39d636034f806b2bb51165a93774ab79?s=128

gaussbeam

November 25, 2016
Tweet

Transcript

  1. IdentifiableUIKit hanyu 2016.11.25 shinagawa.swift #1

  2. 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
  3. Interface Builderʹ΋ͬͱؤுͬͯ΄͍͜͠ͱ ͦͷ̎ ɹഎܠ৭͸ΞϓϦͷςʔϚΧϥʔͰ 0, ɹ͜͜͸ΞϓϦͷςʔϚΧϥʔͰ ɹ͜͜΋ΞϓϦͷςʔϚΧϥʔͰ … 0, ʜ

    ɹ͝ΊΜɺςʔϚΧϥʔมߋʹͳͬͨ
  4. IdentifiableUIKit •ϏϡʔͷελΠϧΛIDͰࢦఆ •Interface Builder্(=Ϗϧυෆཁ)Ͱଈ࣌൓ө •ελΠϧ͸ࣗ༝ʹఆٛͰ͖Δ

  5. DEMO

  6. @IBDesignable class IdentifiableView: UIView { @IBInspectable var … ɹoverride drawRect(rect:

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

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

    protocol ColorStyleType { static var colorDic: [String: UIColor] { get } } @IBDesignable class IdentifiableView: UIView, ColorIdentifiable { … } ϏϡʔͷελΠϧΛIDͰࢦఆ →Ϗϡʔʹ(ColorStyleTypeͷม਺Λ௨ͯ͡)ελΠϧͷࣙॻΛ࣋ͨͤΔ
  9. 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Λఆٛ͠
  10. !*#%FTJHOBCMF*EFOUJpBCMF7JFX .Z7JFX .Z$PMPS4UZMF $PMPS4UZMF5ZQF !*#*OTQFDUBCMFCBDLHSPVOE$PMPS,FZ 1: αϒΫϥεΛఆٛ 2: Interface BuilderͰIDΛࢦఆ

    ֓೦ਤ ݉ ࢖͍ํ .Z7JFX4UZMF 7JFX4UZMF5ZQF
  11. IdentifiableUIKit •ϏϡʔͷελΠϧΛIDͰࢦఆ •Interface Builder্(=Ϗϧυෆཁ) Ͱଈ࣌൓ө •ελΠϧ͸ࣗ༝ʹఆٛͰ͖Δ Sorry, it’s for Swift

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