ReactiveSwift 记录学习

作者: AT19 | 来源:发表于2018-01-23 15:03 被阅读14次

    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

    <2>代码参照大神 : 深渊漫步者亚尔特留斯

    <3>代码地址

    相关文章

      网友评论

        本文标题:ReactiveSwift 记录学习

        本文链接:https://www.haomeiwen.com/subject/rxusaxtx.html