[๐ŸŽWWDC21] Meet the UIKit button system

Kioยท2022๋…„ 3์›” 27์ผ
1

WWDC

๋ชฉ๋ก ๋ณด๊ธฐ
2/4

Meet the UIKit button system (WWDC21) ์„ ๋ณด๊ณ  ์ •๋ฆฌํ•ด๋ณธ ๊ธ€์ž„์„ ์ฐธ๊ณ ํ•ด์ฃผ์„ธ์š”.



Buttons

iOS 15 ํ™˜๊ฒฝ์—์„œ button ์„ ์–ด๋–ป๊ฒŒ ๋” ์ข‹๊ฒŒ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋Š”์ง€ ์•Œ์•„๋ณด๊ณ ์ž ํ•ฉ๋‹ˆ๋‹ค.


4 basic styles (iOS 15)

๊ธฐ๋ณธ์ ์œผ๋กœ ์œ„ 4๊ฐ€์ง€์˜ basic ์Šคํƒ€์ผ์„ ์ œ๊ณต


More features

  • Dynamic type: default
  • Mulitline: ๋ฒ„ํŠผ ์‹œ์Šคํ…œ์— ์ž๋™ ์ ์šฉ
  • Accessibility: ๋ฐœ์ƒํ•˜๋Š” ๋ชจ๋“  ๋ฒ„ํŠผ์— ์ ‘๊ทผ์„ฑ ๊ฐ•ํ™”
  • Easier customization



๊ทธ๋Ÿฌ๋ฉด ๋ฐ”๋€ ๊ฒŒ ๋ญ๋ƒ?

1. Button configuration

// 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 ์ด ํ˜ธ์ถœ๋˜์–ด ์ฒ˜๋ฆฌ๋œ๋‹ค.

Activity indicator

showActivityIndicator = true ๋กœ ๋งŒ๋“ค์–ด์ฃผ๋ฉด activity indicator ๋ฅผ ๋ฒ„ํŠผ์— ์ถ”๊ฐ€ํ•˜๊ณ  App ์‚ฌ์šฉ์ž์—๊ฒŒ ํ˜„์žฌ ๋ฌด์–ธ๊ฐ€ ์ผ์–ด๋‚˜๊ณ  ์žˆ๋‹ค๋Š” ๊ฑธ ์•Œ๋ฆด ์ˆ˜ ์žˆ๋‹ค.


Semantic styling

์ด์ „์—๋Š” ๊ธฐ์กด ๋ฒ„ํŠผ์„ ์žฌ๊ตฌ์„ฑ ํ•˜๋ ค๋ฉด ์•„๋ž˜์‚ฌํ•ญ์„ ๋ฐ”๊ฟจ์–ด์•ผ ํ–ˆ๋‹ค.

  • baseBackgroundColor
  • BaseForegroundColor
  • cornerStyle
  • buttonSize

ํ•˜์ง€๋งŒ ์ง€๊ธˆ์€ ์•„๋ž˜์˜ ํ˜•ํƒœ์— ๋”ฐ๋ผ ๊ฐ„๋‹จํ•˜๊ฒŒ ์ปค์Šคํ…€์ด ๊ฐ€๋Šฅํ•˜๋‹ค.

  • Normal
  • Pressed
  • Disabled



2. Toggle buttons

๊ธฐ์กด์— 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()



3. Pop-up Buttons

  • ๊ธฐ์กด์— 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

profile
Someday_iOS_Dev

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