iOS View Class Design Basic

iOS View Class Design Basic

Swift愛好会 vol.40

B79e8f240b4b730fb692ab93ad42a89b?s=128

darquro

May 10, 2019
Tweet

Transcript

  1. 1.

    Re:valua t ion https://fril.jp/ L ead & Delight User F

    irst Ownership Fail Smart J047JFXΫϥεઃܭجຊ .BZ BU4XJGUѪ޷ձWPM
  2. 3.
  3. 6.
  4. 15.

      "UPNJD%FTJHO 1BHFT ʢϖʔδʣ 5FNQMBUFT ʢςϯϓϨʔτʣ YYYY YYYY YYYY

    YYYY YYYY YYYY YYYY YYYY =  YYY YYYYYYYYYYYYYYY YYY YYY YYYYYYYYYYYYYYY
  5. 16.

      .PMFDVMFTʢ෼ࢠʣ .PMFDVMFTʢ෼ࢠʣ w 6**NBHF7JFX ݪࢠ ͱ
 6*-BCFM ݪࢠ

    ͕ਫฏʹฒͼɺ
 ؙ֯ͷ࿮ઢ ݪࢠ Λ࣋ͭ7JFX
 
 3PVOEFE$PSOFS8JUI*DPO-BCFM
  6. 21.

      ͜͜·Ͱͷ·ͱΊ w ΞϓϦέʔγϣϯΛ࡞Δ্ͰͷҰൠతͳઃܭཧ࿦ w ΞʔΩςΫνϟʔ .7$ .71 .77.

    $MFBO "SDIJUFDUVSF 3FEVY FUDʜ  w σβΠϯύλʔϯ 'BDUPSZ 1SPUPUZQF  4JOHMFUPO 0CTFSWFS FUDʜ
  7. 22.

      ͜͜·Ͱͷ·ͱΊ w ΞϓϦέʔγϣϯΛ࡞Δ্ͰͷҰൠతͳઃܭཧ࿦ w ΞʔΩςΫνϟʔ .7$ .71 .77.

    $MFBO "SDIJUFDUVSF 3FEVY FUDʜ  w σβΠϯύλʔϯ 'BDUPSZ 1SPUPUZQF  4JOHMFUPO 0CTFSWFS FUDʜ ੹຿ͷ෼཭
  8. 25.

      ᶃ9*#ͰσβΠϯ͢Δ7JFX extension NibLoadable where Self: UIView { static

    var nibName: String { return String(describing: self) } static func loadNib(_ bundle: Bundle? = nil) -> UINib { let bundle = bundle ?? Bundle.main return UINib(nibName: nibName, bundle: bundle) } func loadSubviewFromNib() { let nib = Self.loadNib(Bundle(for: type(of: self))) guard let subview = nib.instantiate(withOwner: self, options: nil).first as? UIView else { return } subviews.forEach { $0.removeFromSuperview() } addSubview(subview) setNeedsUpdateConstraints() } func fitConstraintsSubview() { if let contentView = subviews.first { contentView.translatesAutoresizingMaskIntoConstraints = false NSLayoutConstraint.activate([ contentView.topAnchor.constraint(equalTo: self.topAnchor), contentView.leftAnchor.constraint(equalTo: self.leftAnchor), contentView.rightAnchor.constraint(equalTo: self.rightAnchor), contentView.bottomAnchor.constraint(equalTo: self.bottomAnchor) ]) } } }
  9. 26.

      ᶃ9*#ͰσβΠϯ͢Δ7JFX required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder)

    setup() } override init(frame: CGRect) { super.init(frame: frame) setup() } override func prepareForInterfaceBuilder() { super.prepareForInterfaceBuilder() setup() } private func setup() { loadSubviewFromNib() } override func updateConstraints() { fitConstraintsContentView() super.updateConstraints() }
  10. 27.

      ᶄ!*#%FTJHOBCMFɺ!*#*OTQFDUBCMFΛ࢖͏ @IBDesignable final class RoundedCornerWithIconLabel: UIView { @IBInspectable

    var cornerRadius: CGFloat = -1 @IBInspectable var borderColor: UIColor = ColorPalette.textGray @IBInspectable var borderWidth: CGFloat = 1 @IBInspectable var text: String = "Label" @IBInspectable var textColor: UIColor = ColorPalette.textGray @IBInspectable var isImageShown: Bool = false @IBInspectable var image: UIImage? @IBInspectable var imageTintColor: UIColor = ColorPalette.textGray
  11. 28.

      ᶄ!*#%FTJHOBCMFɺ!*#*OTQFDUBCMFΛ࢖͏ @IBInspectable var text: String = "Label" {

    didSet { setText(text) } } private func setText(_ value: String) { label.text = value label.sizeToFit() }
  12. 29.

      ᶅQSFQBSF'PS*OUFSGBDF#VJMEFSΛ࢖͏ required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder)

    setup() } override init(frame: CGRect) { super.init(frame: frame) setup() } override func prepareForInterfaceBuilder() { super.prepareForInterfaceBuilder() setup() } private func setup() { loadSubviewFromNib() setCornerRadius(cornerRadius) setBorderColor(borderColor) setBorderWidth(borderWidth) setImageShown(isImageShown) setImage(image) setImageTintColor(imageTintColor) setTextColor(textColor) setText(text) setTextFontSize(textFontSize) }
  13. 30.

      ᶆMB[ZWBS*OJUJBMJ[BUJPO$MPTVSFΛ࢖͏ @IBDesignable final class ItemDetailItemSalesLabelsContainer: UIView { private

    lazy var includeCarriageLabel: UIView = { let label = RoundedCornerWithIconLabel(frame: CGRect(x: 0, y: 0, width: 100, height: 20)) label.labelType = ItemDetailItemSalesLabelType.includeCarriage label.backgroundColor = ColorPalette.lightOrange label.borderWidth = 0 label.isImageShown = true label.image = FLFrilIcon.tagIcon(withSize: 14.0) .image(with: CGSize(width: 14.0, height: 14.0)) .withRenderingMode(.alwaysTemplate) label.imageTintColor = ColorPalette.textWhite label.text = "ૹྉࠐΈ" label.textColor = ColorPalette.textWhite label.setContentHuggingPriority(.defaultHigh, for: .horizontal) return label }()
  14. 31.

      ᶇ0QUJPO4FUΛ࢖͏ struct ItemDetailItemSalesLabelOptionSet: OptionSet { let rawValue: UInt8

    static let includeCarriage = ItemDetailItemSalesLabelOptionSet(rawValue: 1 << 0) static let excludeCarriage = ItemDetailItemSalesLabelOptionSet(rawValue: 1 << 1) static let anonymousCarriage = ItemDetailItemSalesLabelOptionSet(rawValue: 1 << 2) static let nowAvailable = ItemDetailItemSalesLabelOptionSet(rawValue: 1 << 3) } @IBDesignable final class ItemDetailItemSalesLabelsContainer: UIView { var labelSet: ItemDetailItemSalesLabelOptionSet = [] }