iOS纯代码自定义View
- 1.UIGestureRecognizerDelegate
1 | -(instancetype)init { |
1 | -(void)layoutSubviews { |
1 | UIWindow *window = [UIApplication sharedApplication].keyWindow; |
1 | - (void)cancleButtonClick { |
1 | - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{ |
总结一下当我们使用纯代码创建自定义
UIVIew的时候步骤:
1、新建一个继承UIVIew的类;
2、在实现文件中添加子控件(weak声明);
3、重写- (instancetype)initWithFrame:(CGRect)frame初始化子控件但不设置子控件frame;
4、重写- (void)layoutSubviews,设置子控件frame,记得一定要写[super layoutSubviews];
5、提供一个模型属性,在该模型的set方法中为子控件赋值;