티스토리 뷰

728x90
반응형

iOS 15 에서 사용하는 UIButton.ConfigurationUpdateHandler 를 가지고 버튼의 상태에 따라서 대응해보도록 했다.

enum ButtonState {
        case enable
        case disable
    }

    var completeButtonIsEnabled: ButtonState = .disable {
        didSet {
            if completeButtonIsEnabled == .disable {
                completeButton.isEnabled = false
                if #available(iOS 15.0, *) {
                    completeButton.setNeedsUpdateConfiguration()
                }
            } else {
                completeButton.isEnabled = true
                if #available(iOS 15.0, *) {
                    completeButton.setNeedsUpdateConfiguration()
                }
            }
        }
    }

// MARK: - #available(iOS 15.0, *)
        if #available(iOS 15.0, *) {
            let config = UIButton.Configuration.filled()
            completeButton.configuration = config

            let configHandler: UIButton.ConfigurationUpdateHandler = { button in
                switch button.state {
                case .disabled:
                    button.configuration?.title = "완료"
                    // button.configuration?.baseBackgroundColor = .inputBlack2
                    // button.configuration?.baseForegroundColor = .hintGray1
                default:
                    button.configuration?.title = "완료"
                    // button.configuration?.baseBackgroundColor = .mainBlue
                    // button.configuration?.baseForegroundColor = .white1
                }
            }
            completeButton.configurationUpdateHandler = configHandler
        } else {
            completeButton.setTitle("완료", for: .normal)
            // completeButton.setTitleColor(.white1, for: .normal)
        //        completeButton.setBackgroundImage(, for: .normal)

        // completeButton.setTitleColor(.hintGray1, for: .disabled)
        //        completeButton.setBackgroundImage(, for: .disabled)
        }
728x90
반응형
댓글
최근에 올라온 글
최근에 달린 댓글
글 보관함
«   2024/11   »
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
링크
Total
Today
Yesterday