第一 :UIControl 的继承。
UIControl 是继承与 UIView的。而 UIView继承与UIResponder的。然后 UIResponder 继承与 NSObject的。图形解释如下:
第二:UIcontrol 的方法详细解释。
// ZSJButton.h
// 基础(一)
// Created by 周双建 on 16/4/5.
// Copyright © 2016年 周双建. All rights reserved.
#import <UIKit/UIKit.h>
@interface ZSJButton : UIControl{
@public
//标题
UILabel * ZSJButtonTitle;
//图片
UIImageView * ZSJButtonImageView;
}
@end
// ZSJButton.m
// 基础(一)
// Created by 周双建 on 16/4/5.
// Copyright © 2016年 周双建. All rights reserved.
#import "ZSJButton.h"
@implementation ZSJButton
-(instancetype)initWithFrame:(CGRect)frame{
if (self == [super initWithFrame:frame]) {
self.backgroundColor = [[UIColor whiteColor]colorWithAlphaComponent:1.0f];
self.layer.borderWidth = 0.5f;
self.layer.borderColor = [[UIColor lightGrayColor] CGColor];
self->ZSJButtonTitle = [[UILabel alloc]initWithFrame:CGRectMake(4.0f, 4.0f, frame.size.width-8.0f, frame.size.height - 8.0f)];
self->ZSJButtonTitle.text = @"ZSJButton";
self->ZSJButtonTitle.textColor = [[UIColor blackColor] colorWithAlphaComponent:1.0f];
self->ZSJButtonTitle.font = [UIFont systemFontOfSize:20.0f];
self->ZSJButtonTitle.textAlignment = NSTextAlignmentCenter;
[self addSubview:self->ZSJButtonTitle];
}
return self;
}
// 这是开始启用跟踪事件
-(BOOL)beginTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event{
if (touch.timestamp == 2.0f) {
// 设置点击多长时间,才触发事件
}
if (touch.tapCount == 3) {
// 设置点击的次数,连续点击
}
return [super beginTrackingWithTouch:touch withEvent:event];