기존 UIButton 구성 방식에서는 버튼 객체를 생성한 후 setTitle, setImage 등의 메서드를 통해 버튼의 모양을 구성해야 했습니다1. 이 방식은 코드가 길어지고 직관적이지 않았으며, 다양한 상태에 따른 스타일링이 복잡했습니다.
private let button = UIButton()
button.setTitle("Button", for: .normal)
button.setTitleColor(.systemBlue, for: .normal)
button.setImage(UIImage(systemName: "heart"), for: .normal)`
기존 방식:
let button = UIButton()
button.setTitle("Normal", for: .normal)
button.setTitle("Highlighted", for: .highlighted)
button.backgroundColor = .black
Configuration 방식:
var config = UIButton.Configuration.filled()
config.title = "Title"
config.subtitle = "Subtitle"
config.image = UIImage(systemName: "swift")
config.baseBackgroundColor = .darkGray
let button = UIButton(configuration: config)