use*_*603 2 objective-c uilabel ios
我正在尝试子类UILabel.第一次尝试涉及我的自定义UILabel只是将属性设置adjustsFontSizeToFitWidth为YES.问题是我是iOS编程的新手,并且不确定放置此代码的位置.我尝试了下面的代码,但它们从未被调用过.
- (id)initWithFrame:(CGRect)frame
{
NSLog(@"init custom label");
self = [super initWithFrame:frame];
if (self) {
// Initialization code
self.adjustsFontSizeToFitWidth=YES;
}
return self;
}
- (id)init
{
NSLog(@"init custom label");
self = [super init];
if (self) {
// Initialization code here.
self.adjustsFontSizeToFitWidth=YES;
}
return self;
}
Run Code Online (Sandbox Code Playgroud)
我通过使用它得到它的工作:
lblCustom = [lblCustom init];
Run Code Online (Sandbox Code Playgroud)
但有没有我可以自动调用此调用?
在接口构建器中使用标签时,编码使用NSCoder协议:
- (id)initWithCoder:(NSCoder *)aDecoder
{
NSLog(@"init custom label");
self = [super initWithCoder:aDecoder];
if (self) {
// Initialization code here.
self.adjustsFontSizeToFitWidth=YES;
}
return self;
}
Run Code Online (Sandbox Code Playgroud)
我所做的是创建一个方法来设置我的自定义UI对象,并让所有init调用此方法.
| 归档时间: |
|
| 查看次数: |
1734 次 |
| 最近记录: |