์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
- SwiftUI ํํ ๋ฆฌ์ผ
- ํ๋ก๊ทธ๋๋จธ์ค
- GCD
- duno
- URLSession
- BFS
- ๋์ ๊ณํ๋ฒ
- APPJAM
- HAVIT
- ์ฐ์ํ์ค๋ถ๋ถ์์ด์ํฉ
- ๋ค์ด๋๋ฏนํ๋ก๊ทธ๋๋ฐ
- SOPT
- dfs
- algorithm
- 0์ด๋์ด์๋๊ธธ
- concurrency
- algoritm
- ๊ธฐ์ด๋ฌธ๋ฒ
- GroupBy
- IOS
- ๊ณ ๋์ kit
- SQL
- DynamicProgramming
- Til
- binarySearch
- SwiftUI Tutorials
- discardableResult
- Swift
- SwiftUI
- ์ด์งํ์
- Today
- Total
suvera-dev ๐ฅฆ
iOS ) iOS 15 UIButton.ConfigurationUpdateHandler ๋ณธ๋ฌธ
UIButton.ConfigurationUpdateHandler
: A closure to update the configuration of a button.
๋ฒํผ์ ๊ตฌ์ฑ์ ์ ๋ฐ์ดํธ ํ๊ธฐ ์ํ ํด๋ก์
private let nextButton: UIButton = {
// ๋ฒํผ์ ์์ฑ์ ์ ์ํด์ฃผ๋ ์ฝ๋ ์๋ต
let buttonStateHandler: UIButton.ConfigurationUpdateHandler = { button in
switch button.state {
case .normal:
button.configuration?.background.backgroundColor = .havitPurple
case .disabled:
button.configuration?.background.backgroundColor = .gray002
default:
return
}
}
button.configurationUpdateHandler = buttonStateHandler
return button
}()
๋ฒํผ์ ์ํ์ ๋ง๊ฒ UI๋ฅผ ๋ณ๊ฒฝํด์ฃผ๋ ๋ถ๋ถ์์ ์ฌ์ฉ !
( ์งํํ ํ๋ก์ ํธ์ ์ต์ ๋ฒ์ ์ด iOS 15์์ ๊ณ ๋ คํ์ฌ UIButton.ConfigurationUpdateHandler๋ฅผ ์ฌ์ฉํด ๋ณด์์ต๋๋ค ! )
๐ฅ ์ฐธ๊ณ ํ ๋ธ๋ก๊ทธ์ ์์
In the old day, we can set some of that in state-dependent property setter methods.
With the coming of UIButton.Configuration, Apple goes with a new approach that is more flexible than the previous API.
๊ธฐ์กด : ๋ฒํผ์ ์ํ์ ๋ฐ๋ผ ํ๋์ฉ ์จ์ฃผ๋ ์ ์ ์ธ ๋ฐฉ๋ฒ / ๋ฉ์๋์์ ์ผ๋ถ๋ถ์ ์ค์ ํด์ค !
=> UIButton.Configuration ์ ํตํด ๋ ์ ์ฐํ ์ ๊ทผ ๋ฐฉ์์ ์ฌ์ฉ !
func setTitle(_ title: String?, for state: UIControl.State)
func titleColor(for: UIControl.State) -> UIColor?
func setBackgroundImage(UIImage?, for: UIControl.State)
button.setTitle("Normal", for: .normal)
button.setTitle("Selected", for: .selected)
button.setBackgroundImage(UIImage(named: "foo"), for: .normal)
โจ ๋ฒํผ์ ๋ด๋ถ ์ํ ๋ณ๊ฒฝ์ ๋ฐ๋ฅธ UIButton.ConfigurationUpdateHandler ์ฌ์ฉ ์์
var configuration = UIButton.Configuration.filled()
configuration.baseBackgroundColor = UIColor.systemPink
configuration.buttonSize = .large
let handler: UIButton.ConfigurationUpdateHandler = { button in // 1
switch button.state { // 2
case [.selected, .highlighted]:
button.configuration?.title = "Highlighted Selected"
case .selected:
button.configuration?.title = "Selected"
case .highlighted:
button.configuration?.title = "Highlighted"
case .disabled:
button.configuration?.title = "Disabled"
default:
button.configuration?.title = "Normal"
}
}
let button = UIButton(configuration: configuration, primaryAction: nil)
button.configurationUpdateHandler = handler // 3
let selectedButton = UIButton(configuration: configuration, primaryAction: nil)
selectedButton.isSelected = true
selectedButton.configurationUpdateHandler = handler // 4
let disabledButton = UIButton(configuration: configuration, primaryAction: nil)
disabledButton.isEnabled = false
disabledButton.configurationUpdateHandler = handler // 5
<1> A update handler get called everytime button state changes.
<2> We set different title based on button.state. We can apply to a single state or combination just like we did with .setTitle("Highlighted Selected", for: [.selected, .highlighted]).
<3, 4, 5> We can use the same handler for all buttons.
๋ฒํผ ์ํ๊ฐ ๋ณ๊ฒฝ๋ ๋ ๋ง๋ค ์ ๋ฐ์ดํธ ํธ๋ค๋ฌ ํธ์ถ
๋ฒํผ ์ํ์ ๋ฐ๋ผ ์ ๋ชฉ์ ๋ฐ๊ฟ์ฃผ๊ธฐ !
๋ชจ๋ ๋ฒํผ์ ๋์ผํ ํธ๋ค๋ฌ ์ฌ์ฉ๊ฐ๋ฅ
์์ ๋ณด์ฌ์ค ์์๋ ๋ฒํผ์ ๋ด๋ถ์ํ ๋ณ๊ฒฝ์ ๋ฐ๋ฅธ ์์์์ต๋๋ค !
์ด ๋ฟ๋ง ์๋๋ผ ๋ฒํผ์ด ๋น์ฆ๋์ค ๋ก์ง์ ๋ฐ๋ฅธ ๋ณ๊ฒฝ๊ณผ ๊ฐ์ด ์ธ๋ถ์ํ ๋ณ๊ฒฝ์ ์ ์ํ๋ ๋ถ๋ถ์๋ ์ฝ๊ฒ ๋์ํ ์ ์๋ค๊ณ ํฉ๋๋ค !
์๋์ ๊ฐ์ด Add Item ๋ฒํผ์ ๋๋ ์ ๋ ๋ค๋ฅธ ๋ฒํผ์ ๋๋ฆฌ๋ ํ์๊ฐ ์นด์ดํ ๋์ด ํ์๋๋ค๋์ง.. ์ ๊ฐ์ !
๋ค์์ ๋ ์์๋ณด๋ ๊ฑธ๋ก ..
์ฐธ๊ณ ํ ์ฌ์ดํธ
https://sarunw.com/posts/dynamic-button-configuration/
'iOS' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
iOS) WKWebView (0) | 2022.03.28 |
---|---|
iOS) Modal dismissํ ํ CollectionView reload ํ๊ธฐ (0) | 2022.03.28 |
iOS ) URLSession ์์๋ณด๊ธฐ (2) | 2022.02.28 |
iOS ) GCD ์ฌ์ฉ์ ์ฃผ์ํด์ผํ ์ฌํญ (0) | 2022.02.06 |
iOS) CollectionView Cell - Drag & Drop (0) | 2022.02.01 |