Reputation: 3862
I'm very new to RxSwift and RxCocoa. I want to set image to UIButton by using RxCocoa.
settingButton.rx.image(for: .normal).onNext(UIImage.init(named: "closeButton"))
Any one have idea how to set image to UIButton? Am i doing right?
Upvotes: 1
Views: 1466
Reputation: 1770
Another way:
viewModel.image
.bind(to: button.rx.image(for: .normal))
.disposed(by: disposeBag)
Upvotes: 0
Reputation: 274105
I don't recommend you to set a button's image reactively. If you don't have any special reasons for doing this, do it the normal (imperative) way:
settingButton.setImage(UIImage.init(named: "closeButton"), for: .normal)
Here's how you do it reactively, no need for asObserver
and stuff:
button.rx.image().onNext(UIImage.init(named: "closeButton"))
Upvotes: 3