После RxCocoa
, Reactive
также расширяется UIButton title
или attributedTitle
, чтобы связать его
Пожалуйста, проверьте эту ссылку [RxSwift / UIButton + Rx.swift] (https://github.com/ReactiveX/RxSwift/blob/master/RxCocoa/iOS/UIButton%2BRx.swift)
extension Reactive where Base: UIButton {
/// Reactive wrapper for `setTitle(_:for:)`
public func title(for controlState: UIControl.State = []) -> Binder<String?> {
return Binder(self.base) { button, title -> Void in
button.setTitle(title, for: controlState)
}
}
}
extension Reactive where Base: UIButton {
/// Reactive wrapper for `setAttributedTitle(_:controlState:)`
public func attributedTitle(for controlState: UIControl.State = []) -> Binder<NSAttributedString?> {
return Binder(self.base) { button, attributedTitle -> Void in
button.setAttributedTitle(attributedTitle, for: controlState)
}
}
}
Таким образом, вы можете привязать свое полное имя BehaviorSubject к кнопке, как ваша метка кода образца
vm.fullName.bind(to: someButton.rx.title()).disposed(by: bag)