Meet the UIKit button system (WWDC21) ์ ๋ณด๊ณ ์ ๋ฆฌํด๋ณธ ๊ธ์์ ์ฐธ๊ณ ํด์ฃผ์ธ์.
iOS 15
ํ๊ฒฝ์์button
์ ์ด๋ป๊ฒ ๋ ์ข๊ฒ ๋ง๋ค ์ ์๋์ง ์์๋ณด๊ณ ์ ํฉ๋๋ค.
๊ธฐ๋ณธ์ ์ผ๋ก ์ 4๊ฐ์ง์ basic ์คํ์ผ์ ์ ๊ณต
๊ทธ๋ฌ๋ฉด ๋ฐ๋ ๊ฒ ๋ญ๋?
// Create the Sign In button
let signInButton = UIButton(type: .system
signInButton.configuration = .filled() // โ
NEW
signInButton.setTitle("Sign In", for: [])
filled()
๋ฉ์๋๋ฅผ ํตํด, ๋ฒํผ์ ์์กฐ ์์์ผ๋ก ์ฑ์์ง ๋ฐฐ๊ฒฝ์ผ๋ก ๋ฒํผ์ ๊ตฌ์ฑํฉ๋๋ค.
more than just style!1โฉ
์คํ์ผ ๋ง๊ณ ๋ ๋ค๋ฅธ ๊ฒ ์๋ค๋ฉด!
// Create the Add to Cart button
var config = UIButton.Configuration.tinted() // โ
NEW
config.title = "Add to Cart"
addToCartButton = UIButton(configuration: config, primaryAction: ...)
Add to Cart
๋ฒํผ์ tinted ์คํ์ผ ์ ์ฉ
// Create the Add to Cart button
var config = UIButton.Configuration.tinted()
config.title = "Add to Cart"
config.image = UIImage(systemName: "cart.badge.plus" // โ
NEW
config.imagePlacement = .trailing // โ
NEW
addToCartButton = UIButton(configuration: config, primaryAction: ...)
๋ฒํผ์ ์ด๋ฏธ์ง๋ฅผ ์ถ๊ฐํ๊ณ , ๋ฒํผ ์ด๋ฏธ์ง ์์น๋ฅผ
.trailing
์ ์์น
// Customize image with a configurationUpdateHandler
addToCartButton.configurationUpdateHandler = { [unowned self] button in
var config = button.configuration
config?.image = button.isHighlighted ? UIImabe(systemName: "cart.fill.badge.plus") : UIImage(systemName: "cart.badge.plus"
button.configuration = config
developer.apple - configurationUpdateHandler
- ์ธ์คํด์ค ํ๋กํผํฐ์ธ
configurationUpdateHandler
๋ฅผ ํตํด ๋ฒํผ์ด ๋๋ ธ์ ๋ ๋ณํ๋ ๊ฒ๋ ์ค์ ์ด ๊ฐ๋ฅํ๋ค.configurationUpdateHandler
๋ cell ๊ตฌ์ฑ์ ๋ํ ์ ๋ฐ์ดํธ๋ฅผ ์ฒ๋ฆฌํ๋ block ์ด๋ค.UIControl์ Instance Property
์ธisHighlighted
์ ๊ฐ์ดtrue
๊ฐ ๋๋ฉดUIButton์ ์ํ
๊ฐ ๋ฐ๋๊ธฐ ๋๋ฌธ์configurationUpdateHandler
์ด ํธ์ถ๋์ด ์ฒ๋ฆฌ๋๋ค.
showActivityIndicator = true
๋ก ๋ง๋ค์ด์ฃผ๋ฉดactivity indicator
๋ฅผ ๋ฒํผ์ ์ถ๊ฐํ๊ณ App ์ฌ์ฉ์์๊ฒ ํ์ฌ ๋ฌด์ธ๊ฐ ์ผ์ด๋๊ณ ์๋ค๋ ๊ฑธ ์๋ฆด ์ ์๋ค.
์ด์ ์๋ ๊ธฐ์กด ๋ฒํผ์ ์ฌ๊ตฌ์ฑ ํ๋ ค๋ฉด ์๋์ฌํญ์ ๋ฐ๊ฟจ์ด์ผ ํ๋ค.
- baseBackgroundColor
- BaseForegroundColor
- cornerStyle
- buttonSize
ํ์ง๋ง ์ง๊ธ์ ์๋์ ํํ์ ๋ฐ๋ผ ๊ฐ๋จํ๊ฒ ์ปค์คํ ์ด ๊ฐ๋ฅํ๋ค.
- Normal
- Pressed
- Disabled
๊ธฐ์กด์
toggle buttons
์ด ์๋ ๊ฒ ์๋๋ค.์บ๋ฆฐ๋์ UIBarButtonItem ์์๋ ๋ณผ ์ ์์ผ๋ฉฐ,toggle buttons
์ ํตํด ์์ผ ์ธ๋ถ ์ ๋ณด๋ฅผon-off
๊ฐ๋ฅํ๋ค.
iOS 15
์์๋toggle buttons
๋ฐ๋ ์
์ ๊ทธ๋ฆผ์ฒ๋ผ
In Stock Only
๋ฒํผ์์ ํ or ๋น์ ํ
์ ์ํ๋ก ์ค์ ๊ฐ๋ฅํ๋ค. ์ด๊ฑดlabel
์ด ์๋๊ธฐ ๋๋ฌธ์ ์ฌ์ฉ์์๊ฒ ํ์คํ๊ฒ ๋ณด์ฌ์ค ์ ์๋ค.
// Toggle button
// UIAction setup
let stockToggleAction = UIAction(title: "In Stock Only") { _ in
toggleStock()
}
// The button
let button = UIButton(primaryAction: stockToggleAction)
button.changesSelectionAsPrimaryAction = true // โ
// Initial state
button.isSelected = showingOnlyInStock()
- ๊ธฐ์กด์
pull-down buttons
๊ณผ ๋น์ทํ ํํpop-up buttons
ํด๋ฆญ์ ํ๋์ ํญ๋ชฉ ์ ํ ๊ฐ๋ฅ- ์ ํ๋ ํญ๋ชฉ์ ํ๋ฉด์ ํ์
// Pop-up button
let colorClosure = { (action: UIAction) in
updateColor(action.title)
}
let button = UIButton(primaryAction: nil)
button.menu = UIMenu(children: [
UIAction(title: "Bondi Blue", handler: colorClosure),
UIAction(title: "Flower Power", state: .on, handler: colorClosure)
])
button.showsMenuAsPrimaryAction = true // โ
button.changesSelectionAsPrimaryAction = true
// Update to the currently set one
updateColor(button.menu?.selectedElements.first?.title)
// Update the selection
(button.menu?.children[selectedColorIndex()] as? UIAction)?.state = .on
Meet the UIKit button system (WWDC21)
developer.apple - filled()
developer.apple - configurationUpdateHandler