typedef QGLabel *(^Block3)(UIColor *color);
@interface QGLabel : UILabel
@property (nonatomic, copy) Block3 block2;
@property (nonatomic, copy) Block3 block3;
@property (nonatomic, copy) NSString *(^block)(NSNumber *);
@end
@implementation QGLabel
#pragma mark - 设置初始化数据
/** 设置数据 */
-(void)setupData{
self.h = ^NSString *(NSNumber *num) {
NSLog(@"%@", num);
};
__weak typeof(self) weakSelf = self;
self.block2 = ^QGLabel *(UIColor *color) {
weakSelf.textColor = color;
return weakSelf;
};
}
-(Block3)block3{
__weak typeof(self) weakSelf = self;
return ^QGLabel *(UIColor *color) {
weakSelf.backgroundColor = color;
return weakSelf;
};
}
-(void)setBlock:(NSString *(^)(NSNumber *))block{
NSLog(@"block的 set 方法");
}
-(NSString *(^)(NSNumber *))block{
}
@end
调用 调用了block3的 get 方法
label.block3([UIColor redColor]);
赋值 调用了block3的 set 方法
__weak typeof(self) weakSelf = self;
self.block3 = ^QGLabel *(UIColor *color) {
weakSelf.textColor = color;
return weakSelf;
};
说明:
我们可以把 block 当做一个可以存储一段代码的属性
如图的 block2 和 block3 我们就实现了链式编程
label.block3([UIColor yellowColor]).block2([UIColor redColor]);