RxSwift/RxCocoa/iOS/UIButton+Rx.swift
Jérôme Alves 10ff55cfba Moves RxCocoa extensions from rx_ syntax to rx. syntax.
The main work is done in this commit but the feature it's still "work in progress"
2016-08-09 00:17:38 +02:00

69 lines
1.3 KiB
Swift

//
// UIButton+Rx.swift
// RxCocoa
//
// Created by Krunoslav Zaher on 3/28/15.
// Copyright © 2015 Krunoslav Zaher. All rights reserved.
//
#if os(iOS)
import Foundation
#if !RX_NO_MODULE
import RxSwift
#endif
import UIKit
extension Reactive where Base: UIButton {
/**
Reactive wrapper for `TouchUpInside` control event.
*/
public var tap: ControlEvent<Void> {
return controlEvent(.touchUpInside)
}
}
#endif
#if os(tvOS)
import Foundation
#if !RX_NO_MODULE
import RxSwift
#endif
import UIKit
extension Reactive where Base: UIButton {
/**
Reactive wrapper for `PrimaryActionTriggered` control event.
*/
public var primaryAction: ControlEvent<Void> {
return controlEvent(.primaryActionTriggered)
}
}
#endif
#if os(iOS) || os(tvOS)
import Foundation
#if !RX_NO_MODULE
import RxSwift
#endif
import UIKit
extension Reactive where Base: UIButton {
/**
Reactive wrapper for `setTitle(_:controlState:)`
*/
public func title(controlState: UIControlState = []) -> AnyObserver<String?> {
return UIBindingObserver<UIButton, String?>(UIElement: self.base) { (button, title) -> () in
button.setTitle(title, for: controlState)
}.asObserver()
}
}
#endif