I am new to RxSwift
, so I wonder If it is possible to update UIButton
title and select the action accordingly using RxSwift
.
Say, I have a custom UIButton
inside my UITableViewCell
which I intend it to trigger a set of custom actions when the user taps, (e.g: like or dislike image or post or whatever...)
So, is that possible, for instance, to set the custom title, image, and action of a UIButton
accordingly, and update the UI..
For more explanation of the point, say, I have two actions user can interact with the button: func imageDisliked()
and imageLiked()
, So when the Image is disliked, I want the button to set its title "imageDisliked" and its icon "dislikeIcon" and vice versa..
is that possible with RxSwift
?
Rx is all about cause and effect. Some things cause events to happen and some things listen for an event and do something as a result.
A button tap
myButton.rx.tap
emits events, it's a cause. A button's titlemyButton.rx.title(for: .normal)
is an effect. So is its imagemyButton.rx.image(for: .normal)
.As for your
imageLiked()
andimageDisliked()
, at this point they sound like effects, but you haven't outlined the causes properly yet.So the answer to your question is, yes it is possible to update a UIButton. You just need to outline what effects you want, and for each effect you need to outline the cause or causes.