Reputation: 61774
This is what I simply try to achieve using:
let observable = Observable.combineLatest(loginProperty.asObservable(), passwordProperty.asObservable()) { _,_ in
self.viewModel.isValid
}
observable.bind(to: mainView.loginButton.rx.isEnabled).disposed(by: disposeBag)
//observable.bind(to: mainView.loginButton.rx.alpha).disposed(by: disposeBag)
But this can be bound only to isEnabled
property. I would like to also change alpha of my loginButton
. How can I do that?
Upvotes: 3
Views: 1721
Reputation: 6213
You have to write Reactive extension to bind the property.
extension Reactive where Base : UIButton {
public var valid : Binder<Bool> {
return Binder(self.base) { button, valid in
button.isEnabled = valid
button.alpha = 0.5 // You Value as per valid or not
}
}
}
Then write like this to check the Observable value
observable.bind(to: mainView.loginButton.rx.valid).disposed(by: disposeBag)
Upvotes: 10