CombineObject
CombineObject 响应式框架 Swift 版本, Value 和 View 相互绑定。
安装
CocoaPods
pod 'CombineObject'Carthage
github "combineobject/CombineObject-Swift"Package
https://github.com/combineobject/CombineObject-Swift怎么使用
Example1
假如我们界面一个
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)
Example2
比如我们的属性没有我们试图绑定属性 我们想接受到属性变化时候更改值
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
}
}Example3
属性控制
UIProgressView属性
Example4
监听输入框的内容
Example5
监听
UISlider值
Example6
监听
UISwitch的状态
Example6
监听
UItextView值变化
接口文档
目前支持的属性
UIView
- backgroundColor
- userInteractionEnabled
- frame
- alpha
- hidden
UILabel
- text
- font
- textColor
- attributedText
UISwitch
- on
UITextField
- text
- placeholder
UISlider
- value
UIProgressView
- progress
UITextView
- text
扩展UIView的赋值支持属性方法
public func setUIViewCombineValue(_ identifier: CombineIdentifier, _ value: CombineValue?)让其他的对象支持属性绑定
实现
CombineView协议
func setCombineValue(_ identifier:CombineIdentifier, _ value:CombineValue?)自定义赋值
实现属性
bine值的代理方法``
self.color.bine.setCombineValueBlock = { content in
}






