View

  • ํ™”๋ฉด์„ ๊ตฌ์„ฑํ•˜๋Š”๋ฐ ๊ธฐ๋ณธ์ด ๋˜๋Š” class
  • NSObject๋ฅผ ์ƒ์†ํ•œ UIResponder๋ฅผ ์ƒ์†ํ•ด์„œ ๊ตฌ์„ฑ๋จ
  • CustomView๋Š” UIView๋ฅผ ์ƒ์†ํ•จ
  • UIImageView, UILable, UIScrollViewโ€ฆ

๊ฐ€๋Šฅํ•œ ๊ฒƒ๋“ค

  • Drawing
  • Animation
  • Layout
  • subview ๊ด€๋ฆฌ
  • Event Handling
    • UIResponder ์ƒ์†ํ•˜๊ธฐ ๋•Œ๋ฌธ์—, touch์™€ ๊ฐ™์€ event์— ๋ฐ˜์‘ ๊ฐ€๋Šฅ
    • gesture ์ถ”๊ฐ€

์ดˆ๊ธฐํ™”

  • ํ˜•ํƒœ

    // code
    init(frame:)
    init() // default parameter = CGRect.zero
     
    // storyboard
    init(coder:)
  • templates

    override init(frame: CGRect) {
        super.init(frame: frame)
        // write code
    }
     
    required init?(coder: NScoder) {
        super.init(coder: coder)
        // write code
    }

frame & bounds

  • UIView๋Š” ๊ธฐ๋ณธ์ ์œผ๋กœ ์‚ฌ๊ฐํ˜•์ž„
  • ์ด ์ƒํƒœ์—์„œ frame, bounds๋ฅผ ํ†ตํ•ด ํฌ๊ธฐ์™€ ์œ„์น˜ ์กฐ์ •
  • CGRect
    • frame, bounds์˜ ์ž๋ฃŒํ˜•
    • x, y, point ๋ฐ ๊ฐ€๋กœ,์„ธ๋กœ ํฌ๊ธฐ๋ฅผ ๊ฐ€์ง
  • point
    • ์ขŒํ‘œ ์ฒด๊ณ„
    • px * scale์ž„
      • UIScreen.main.scale๋กœ ์ ‘๊ทผ ๊ฐ€๋Šฅ
  • frame
    • superview๋กœ ๋ถ€ํ„ฐ ์ƒํƒœ์ ์ธ ์œ„์น˜ ๋ฐ ํฌ๊ธฐ
    • ์ง‘์˜ ์ฐฝ๋ฌธ์ด๋ผ ์ƒ๊ฐ
  • bounds
    • view์˜ ๋‚ด๋ถ€ ํฌ๊ธฐ
    • ๋ฐฉ์˜ ํฌ๊ธฐ๋ผ ์ƒ๊ฐ
    • ์ฐฝ๋ฌธ๋ณด๋‹ค ๋ฐฉ์ด ๋„“์„ ์ˆ˜ ์žˆ๊ณ , ์ฐฝ๋ฌธ๊ณผ ๋ฐฉ์ด ํฌ๊ธฐ๊ฐ€ ๊ฐ™์„ ์ˆ˜ ์žˆ๋‹ค.
    • ์ฐฝ๋ฌธ ์„ค์น˜ ์œ„์น˜๊ฐ€ ๊ณ ์ •์ด๋ผ๊ณ  ํ–ˆ์„ ๋•Œ, ๋ฐฉ์˜ ์œ„์น˜๋ฅผ ์ด๋ฆฌ๊ฑฐ๋ฆฌ ์›€์ง์ธ๋‹ค๋ฉด ๋ฐฉ์˜ ๋‚ด๋ถ€๋ฅผ ์ฐฝ๋ฌธ์œผ๋กœ ๋ณผ ์ˆ˜ ์žˆ์„ ๊ฒƒ์ด๋‹ค.
    • ์œ„์˜ ์„ค๋ช… ๋ฐฉ์‹์œผ๋กœ ๋™์ž‘ํ•œ๋‹ค.

Subview ๊ด€๋ฆฌ

  • ์ถ”๊ฐ€

    view.addSubview(subview)
  • ์ œ๊ฑฐ

    subview.removeFromSuperView()

LayoutSubviews

  • view ํฌ๊ธฐ ๋ฐ bounds๋“ค์ด ๋ณ€๊ฒฝ๋  ๋•Œ ํ˜ธ์ถœ๋จ
  • layoutSubviews๋ฅผ overrideํ•ด์„œ view์˜ ํ™”๋ฉด ๋ณ€ํ™”์— ๋”ฐ๋ฅธ subview๋“ค์˜ layout ์žฌ์กฐ์ • ๊ฐ€๋Šฅ
  • ๋ณด๋‹ค ๊นŠ์€ ์‚ฌํ•ญ์€ ์ถ”๊ฐ€ ๊ธ€์„ ํ†ตํ•ด ์•Œ์•„๋ณด์ž

์ฃผ์˜ ์‚ฌํ•ญ

  • view ์ ‘๊ทผ์€ ๋ฐ˜๋“œ์‹œ main thread์—์„œ ์ด๋ฃจ์–ด์ ธ์•ผ ํ•จ