重点:
****************************************************
*
* 自定义控件一定按格式来,书写下面三个方法
*
****************************************************
/**
* 从文件中创建一定会调用这个方法
* 从文件中解析一个对象的时候,一定会调用initWithCoder这个方法
*/
- (id)initWithCoder:(NSCoder *)decoder
{
if (self = [super initWithCoder:decoder])
{
[self setup];
}
return self;
}
/**
* 从代码中创建一定会调用这个方法:因为init方法中会调用initWithFrame方法
*/
- (instancetype)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
[self setup];
}
return self;
}
/**
* 初始化
*/
- (void)setup
{
self.titleFont = [UIFont systemFontOfSize:14];
self.titleLabel.font = self.titleFont;
//让内部图标居中
self.imageView.contentMode = UIViewContentModeCenter;
}
补充:
下面这个方法是从XIB方法中创建就会调用这个方法,其实从上面知道,了解了上面的方法就够了
- (void)awakeFromNib
{
}
彩票案例-自定义控件
最新推荐文章于 2025-05-03 16:02:54 发布