iOS, UIView

iDOยท2022๋…„ 1์›” 3์ผ
0

UIKit

๋ชฉ๋ก ๋ณด๊ธฐ
2/2
post-thumbnail
post-custom-banner

๐Ÿงedwith์—์„œ ์˜ˆ์ „์— ๋ดค์—ˆ๋˜ ์Šคํƒ ํฌ๋“œ CS193P ๋ฒˆ์—ญ ๊ฐ•์˜๋ฅผ ๋‹ค์‹œ๋ณด๋˜ ์ค‘ UIView์— ๋Œ€ํ•ด ๊ธฐ๋ณธ์ ์ธ ๋ถ€๋ถ„๋งŒ ๊ฐ„๋žตํ•˜๊ฒŒ ์ •๋ฆฌํ•ด๋ดค์Šต๋‹ˆ๋‹ค.

โ„๏ธ UIView

UIKit ํ”„๋ ˆ์ž„์›Œํฌ์„ ํ†ตํ•˜์—ฌ, ์Šคํฌ๋ฆฐ์— ์ง์‚ฌ๊ฐํ˜• ํ˜•ํƒœ์˜ ์˜ค๋ธŒ์ ํŠธ์ž…๋‹ˆ๋‹ค.

โ„๏ธ init()

  • code & storyboard ์ดˆ๊ธฐํ™”

init(frame: CGRect) // ์ฝ”๋“œ๋กœ UIView ์ƒ์„ฑ์‹œ
init(coder: NSCoder) // ์Šคํ† ๋ฆฌ๋ณด๋“œ์—์„œ UIView ์ƒ์„ฑ์‹œ
  • Example code.
func setup() { ... }

override init(frame: CGRect) {
	super.init(frame: frame)
    setup()
}

required init?(coder aDecoder: NSCoder) {
	super.init(coder: aDecoder)
    setup()
}
๋งŒ์•ฝ UIView๋ฅผ ์ดˆ๊ธฐํ™”ํ•  ํ•„์š”๊ฐ€ ์žˆ์„ ๊ฒฝ์šฐ, ์ฝ”๋“œ๋ฅผ ํ†ตํ•œ init๊ณผ ์Šคํ† ๋ฆฌ๋ณด๋“œ๋ฅผ ์œ„ํ•œ init ๋‘๊ฐœ๋ฅผ ์ƒ์„ฑํ•ด์ฃผ์…”์•ผ ํ•ฉ๋‹ˆ๋‹ค.

โ„๏ธ bount & frame

  • bound: UIView์˜ ํฌ๊ธฐ!

  • frame: UIView์˜ super view ์— ๋”ฐ๋ฅธ ๋ฒ”์œ„

UIView๋ฅผ ํšŒ์ „ ์‹œ์ผฐ์„ ๊ฒฝ์šฐ bound๋Š” ๊ทธ๋ž˜๋กœ์ง€๋งŒ, frame์€ ๋ณ€ํ•˜๋Š” ๊ฑธ ํ†ตํ•ด ๋‘˜์˜ ์ฐจ์ด๋ฅผ ์‰ฝ๊ฒŒ ์ดํ•ดํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

UIView๋ฅผ ๊ทธ๋ฆฌ๋Š”๋ฐ ์žˆ์–ด์„œ๋Š” bound๋ฅผ ์‚ฌ์šฉํ•˜๋Š”๊ฒŒ ๋งž์Šต๋‹ˆ๋‹ค!

- End -

์ด ๊ธ€์€ ์—ฌ๊ธฐ๊นŒ์ง€๊ณ  ๋‹ค์Œ์—, Custom view์—๋Œ€ํ•ด์„œ๋„ ๊ฐ„๋žตํžˆ ์ •๋ฆฌํ•ด๋ด์•ผ๊ฒ ์Šต๋‹ˆ๋‹ค.

๐Ÿง(์•„๋ž˜ ์ฐธ๊ณ ๋‚ด์šฉ์„ ํ†ตํ•ด ๋” ์ž์„ธํ•œ ์ •๋ณด๋ฅผ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค!)
edwith: ์Šคํƒ ํฌ๋“œ CS193P, Chapter5

profile
์ด๊ณณ์€ ์ €๋ฅผ ์œ„ํ•œ iOS ์„ค๋ช…์„œ์ž…๋‹ˆ๋‹ค.
post-custom-banner

0๊ฐœ์˜ ๋Œ“๊ธ€