CombineObjectObjc 1.0.0

CombineObjectObjc 1.0.0

zhangxing 维护。



  • 作者
  • 张行
typora-root-url typora-copy-images-to
./images
./images

CombineObject-Objc

CombineObject 响应式框架 Objective-C 版本,ValueView 相互绑定。

image-20190806101237397

安装

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],@"");

![2019-08-06 10-22-35.2019-08-06 10_24_52](/2019-08-06 10-22-35.2019-08-06 10_24_52.gif)

示例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];
};

![2019-08-06 10-39-10.2019-08-06 10_39_44](/2019-08-06 10-39-10.2019-08-06 10_39_44.gif)

示例3

控制UIProgressView的属性

![2019-08-06 11-18-14.2019-08-06 11_18_55](/2019-08-06 11-18-14.2019-08-06 11_18_55.gif)

示例4

监听输入框内容

![2019-08-06 11-34-01.2019-08-06 11_34_27](/2019-08-06 11-34-01.2019-08-06 11_34_27.gif)

示例5

监听UISlider的值

![2019-08-06 11-45-34.2019-08-06 11_45_56](/2019-08-06 11-45-34.2019-08-06 11_45_56-5063215.gif)

示例6

监听UISwitch的状态

![2019-08-06 11-55-15.2019-08-06 11_55_32](/2019-08-06 11-55-15.2019-08-06 11_55_32.gif)

示例6

监听UItextView值变化

![2019-08-06 12-07-29.2019-08-06 12_07_49](/2019-08-06 12-07-29.2019-08-06 12_07_49.gif)

接口文档

当前支持的属性

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) {
}