Deep_Dev
article thumbnail

๐Ÿ“Œ AutoLayout : StackView ํ™œ์šฉํ•ด์„œ ๊ณ„์‚ฐ๊ธฐ Layout ๊ตฌํ˜„

 

 

 

 

 

 

 

  • 1. StackView๋กœ UIButton ๋ฌถ๊ธฐ ( ๊ฐ€๋กœ๋กœ ๋ฌถ๋“ , ์„ธ๋กœ๋กœ ๋ฌถ๋“  )
  • 2. StackView ๋‚ด์—์„œ ๊ฐ์ฒด๋“ค์˜ ํฌ๊ธฐ ์„ค์ • ( Button ๋ชจ๋‘ ์„ ํƒํ•˜์—ฌ Equals Width )
    • 2-1. Multiplier๋กœ ํฌ๊ธฐ ๋น„์œจ ์„ค์ • ( ์ˆซ์ž 0์ด ์žˆ๋Š” ์ œ์ผ ํ•˜๋‹จ StackView )
    • 2-1. StackView ์œ„์น˜ ์„ค์ •
  • 3. UIButton ํŠน์ • ๋†’์ด๊ฐ’ ์ง€์ •ํ•˜์ง€ ๋ง๊ณ , Aspect Ratio ๋กœ ์„ค์ •ํ•˜์—ฌ Multiplier ๋น„์œจ 1:1 ( -> ์ •์‚ฌ๊ฐํ˜• ์žกํžŒ๋‹ค )

 

๐Ÿ“Œ UIButton ๋‘ฅ๊ธ€๊ฒŒ

 

@IBOutlet weak var myButton : UIButton!

 

myButton.layer.masksToBounds = true

 

๐Ÿ“Œ ์–ผ๋งˆ๋‚˜ ๋‘ฅ๊ธ€๊ฒŒ ? 

myButton.layer.cornerRadius = 50

๋˜๋Š”

myButton.layer.cornerRadius = myButton.layer.frame.size.width / 2

 

 

๐Ÿ“Œ ๋˜๋Š”

 

 

๋ทฐ๋ฅผ ํด๋ฆญํ•˜๊ณ  Identity Inspector๋ฅผ ํด๋ฆญํ•˜๋ฉด ์œ„์™€ ๊ฐ™์ด UserDefined Runtime Attributes ์นธ์ด ์žˆ๋‹ค.

 

ํ”Œ๋Ÿฌ์Šค ๋ฒ„ํŠผ์„ ๋ˆ„๋ฅธ ๋’ค์— ์•„๋ž˜ ํ•ญ๋ชฉ๋“ค์„ ์ถ”๊ฐ€ํ•œ๋‹ค.

 

layer.masksToBounds Boolean YES

layer.cornerRadius Number 50

 

์ˆซ์ž 50 ์ž๋ฆฌ์— ์›ํ•˜๋Š” ๊ฐ’์„ ๋„ฃ์œผ๋ฉด ๋œ๋‹ค.