1.登录demo
<1>核心代码:
//信号
let namesignal = nameTextField.reactive.continuousTextValues
let pswsignal = passwordTextField.reactive.continuousTextValues
let colorSignal1 : Signal<Bool, NoError> = namesignal.map {
text in
return text!.count < 6 ? false : true
}
let colorSignal2 : Signal<Bool ,NoError> = pswsignal.map { text in
return text!.count < 6 ? false : true
}
//合并信号
let colorSignal: Signal<UIColor, NoError> = Signal.combineLatest(colorSignal1, colorSignal2).map{
return $0 && $1 ? .red : .lightGray
}
let validSignal = Signal.combineLatest(colorSignal1, colorSignal2).map{
$0 && $1
}
//Property(首先接收一个初始的值)
let tfColor = Property(initial: .lightGray, then: colorSignal)
let loginEnable = Property(initial: false, then: validSignal)
//属性绑定
loginBtn.reactive.isEnabled <~ loginEnable
loginBtn.reactive.backgroundColor <~ tfColor
swift4.0.gif
<3>代码地址
网友评论