CombineObject 1.0.0

CombineObject 1.0.0

张行维护。



  • 作者
  • 张行

CombineObject

CombineObject 响应式框架 Swift 版本,ValueView 相互绑定。

image-20190806101237397

安装

CocoaPods

pod 'CombineObject'

Carthage

github "combineobject/CombineObject-Swift"

Package

https://github.com/combineobject/CombineObject-Swift

如何使用

示例1

假设我们界面上有一个UIView和一个UILabel,我们希望UIView的背景颜色和UILabel的文本颜色始终保持一致。有多种方法可以实现,我们来看看这个库能做什么。

  • 声明一个变量来控制

    @CombineObjectBind var color = UIColor.gray
  • 将其绑定到视图

    self.displayLabel.bind(identifier: UILabelIdentifier.textColor, combineObject: self._color)
    self.displayView.bind(combineObject: self._color)
  • 更新属性以更新视图

    self.color = UIColor.red
  • 直接更新视图的值

self.displayView.updateBindValue(value: UIColor.blue)

2019-08-06 10-22-35.2019-08-06 10_24_52

示例2

比如我们的属性没有与视图绑定属性,我们想在属性变化时更改值

self._color.bind.combineValueChangedBlock {[weak self] (value) in
    if let boardColor = value as? UIColor {
        self?.displayLabel.layer.borderWidth = 1
        self?.displayLabel.layer.borderColor = boardColor.cgColor
    }
}

2019-08-06 10-39-10.2019-08-06 10_39_44

示例3

属性控制UIProgressView属性

2019-08-06 11-18-14.2019-08-06 11_18_55

示例4

监听输入框的内容

2019-08-06 11-34-01.2019-08-06 11_34_27

示例5

监听UISlider的值

2019-08-06 11-45-34.2019-08-06 11_45_56

示例6

监听UISwitch的状态

2019-08-06 11-55-15.2019-08-06 11_55_32

示例6

监听UItextView的值变化

2019-08-06 12-07-29.2019-08-06 12_07_49

接口文档

目前支持的属性

UIView

  • backgroundColor
  • userInteractionEnabled
  • frame
  • alpha
  • hidden

UILabel

  • text
  • font
  • textColor
  • attributedText

UISwitch

  • on

UITextField

  • text
  • placeholder

UISlider

  • value

UIProgressView

  • 进度

UITextView

  • text

扩展UIView的赋值支持属性方法

public func setUIViewCombineValue(_ identifier: CombineIdentifier, _ value: CombineValue?)

让其他对象支持属性绑定

实现《CombineView》协议

func setCombineValue(_ identifier:CombineIdentifier, _ value:CombineValue?)

自定义赋值

实现属性bin值的代理方法``

self.color.bine.setCombineValueBlock = { content in
}