-
Notifications
You must be signed in to change notification settings - Fork 3
UIButton.setBackgroundColor
S025_신명섭 edited this page Dec 1, 2021
·
1 revision
setBackgroundColor(color: UIColor, for state: UIControl.State)
UIButton의 상태에 따라 backgroundColor를 변경합니다.
func setBackgroundColor(color: UIColor, for state: UIControl.State) {
UIGraphicsBeginImageContext(CGSize(width: 1.0, height: 1.0))
guard let context = UIGraphicsGetCurrentContext()
else { return }
context.setFillColor(color.cgColor)
context.fill(CGRect(x: 0.0, y: 0.0, width: 1.0, height: 1.0))
let backgroundImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
self.setBackgroundImage(backgroundImage, for: state)
}