简体   繁体   English

呈现UITextField时调用什么方法

[英]What method is called when UITextField is rendered

I want to make a subclass of UITextField that change the style of it automatically. 我想做一个UITextField的子类来自动更改它的样式。

I tried to subclass and override the init method: 我试图继承并覆盖init方法:

- (id)init
{
    self = [super init];
    if (self) {
        self.layer.borderWidth = 1.0;
        self.layer.borderColor = [[StyleKit2 blue]CGColor];
        self.layer.cornerRadius = 5.0;
    }
    return self;
}

Then i set this as the custom class in storyboard. 然后,将其设置为情节提要中的自定义类。

But it does not effect the textview. 但这不会影响textview。

You can put the same code in awakeFromNib: 您可以将相同的代码放入awakeFromNib中:

-(void)awakeFromNib
{
    [super awakeFromNib]; 

    self.textFieldx.layer.borderWidth =1.0;
    self.layer.borderColor = [[StyleKit2 blue]CGColor];
    self.layer.cornerRadius = 5.0;

}

You can try to override it in initWithFrame as well. 您也可以尝试在initWithFrame覆盖它。

You can add these attributes in Interface builder in user defined runtime attributes(third tab), except the color. 您可以在用户定义的运行时属性(第三个选项卡)中的“接口”构建器中添加这些属性(颜色除外)。 In interface builder you can set UIColor but you need CGColor for borderColor. 在界面生成器中,您可以设置UIColor,但是您需要CGColor来设置borderColor。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM