typora-root-url | typora-copy-images-to |
---|---|
./images |
./images |
CombineObject-Objc
CombineObject
响应式框架 Objective-C
版本,Value
与 View
相互绑定。
安装
CocoaPods
pod 'CombineObjectObjc'
Carthage
github "combineobject/CombineObject-Objc"
如何使用
示例1
假设我们的界面有一个
UIView
和一个UILabel
,我们想让UIView
的背景颜色和UILabel
的文本颜色保持一致。我们可以有多种方法来实现这一点,让我们看看这个库能做什么。
-
声明一个变量进行控制
/// 声明绑定属性 @property (nonatomic, strong) UIColor *displayViewBackgroundColor; /// 初始化 self.displayViewBackgroundColor = [UIColor grayColor];
-
绑定到视图
/// 绑定到试图默认的 BackgroundColor 属性 self.displayView.viewBind(self.displayViewBackgroundColor.bind,@""); /// 绑定UILabel 的文本颜色 self.displayColorText.viewBind(self.displayViewBackgroundColor.bind,UILabelIdentifier.textColor);
-
更新属性更新视图
/// 更改属性的值 self.displayViewBackgroundColor.wrappedValue = [UIColor redColor];
-
直接更新一个视图的值
/// 更改试图的值
self.displayView.updateWrappedValue([UIColor blueColor],@"");

示例2
比如我们的属性没有绑定到试图,我们想在属性变化时更改值
__weak typeof(self) weakSelf = self;
self.displayViewBackgroundColor.bind.contentChanged = ^(id<CombineValue> _Nonnull content) {
__strong typeof(weakSelf) strongSelf = weakSelf;
strongSelf.displayLabel.layer.borderWidth = 1;
strongSelf.displayLabel.layer.borderColor = [(UIColor *)content CGColor];
};

示例3
控制
UIProgressView
的属性

示例4
监听输入框内容

示例5
监听
UISlider
的值

示例6
监听
UISwitch
的状态

示例6
监听
UItextView
值变化

接口文档
当前支持的属性
UIView
- backgroundColor
- userInteractionEnabled
- frame
- alpha
- hidden
UILabel
- text
- font
- textColor
- attributedText
UISwitch
- on
UITextField
- text
- placeholder
UISlider
- 值
UIProgressView
- 进度
UITextView
- text
UIView
的赋值支持属性方法
扩展- (void)setOtherCombineValue:(id<CombineValue>)value identifier:(NSString *)identifier
让其他对象支持属性绑定
实现
CombineView
协议
- (void)setCombineValue:(id<CombineValue>)value identifier:(NSString *)identifier
自定义赋值
实现属性
bin
值的代理方法
self.color.bine.customSetWrappedValueBlock = ^(CombineBindBlockContent *content) {
}