007-基本知识
一、自定义控件的几个方法
1 #pragma mark - 从文件中解析一个对象的时候就会调用这个方法 2 // 不管是Xib文件还是Storyboard文件,只要是从文件中解析出来的就会调用这个方法 3 - (instancetype)initWithCoder:(NSCoder *)aDecoder 4 { 5 if (self = [super initWithCoder:aDecoder]) { 6 [self setup]; // 初始化方法 7 } 8 return self; 9 } 10 11 #pragma mark - 当一个对象从Xib或者从Storyboard中加载完毕时就会调用一次 12 - (void)awakeFromNib 13 { 14 15 } 16 17 #pragma mark - 当一个对象是通过init方法初始化时调用 18 - (instancetype)initWithFrame:(CGRect)frame 19 { 20 if (self = [super initWithFrame:frame]) { 21 [self setup]; // 初始化方法 22 } 23 return self; 24 } 25 26 #pragma mark - 辅助方法(初始化方法) 27 - (void)setup 28 { 29 // 在这里可以初始化一些东西 30 }
注意:我们在自定义控件的时候,一定要注意方法的适当调用,最好是以下三个方法都写清楚,这样可以做到不管是Xib、Storyboard,还是init初始化控件,都可以做到面面俱到
二、基本知识
1.获取当前设备的系统版本
[[UIDevice currentDevice].systemVersion floatValue]

浙公网安备 33010602011771号