Ios 如何在脚本中为UIView创建init方法?

Ios 如何在脚本中为UIView创建init方法?,ios,properties,subclassing,Ios,Properties,Subclassing,我有一个类PLButton,具有两个属性: @property (strong, nonatomic) UIColor *purpleColor; @property (strong, nonatomic) UIColor *grayColor; 及其初始值设定项: - (instancetype)init { if (self = [super init]) { self.purpleColor = [UIColor colorWithRed:142.0/255.0 green:23

我有一个类
PLButton
,具有两个属性:

@property (strong, nonatomic) UIColor *purpleColor;
@property (strong, nonatomic) UIColor *grayColor;
及其初始值设定项:

- (instancetype)init {
if (self = [super init]) {
    self.purpleColor = [UIColor colorWithRed:142.0/255.0 green:23.0/255.0 blue:126.0/255.0 alpha:1.0];
    self.grayColor = [UIColor colorWithRed:239.0/255.0 green:239.0/255.0 blue:239.0/255.0 alpha:1.0];
}
return self;
}

我还有一个
plventbutton
作为
PLButton
的子类:

和内部初始值设定项:

- (instancetype)init {
if (self = [super init]) {
    return self;
}
return self;
}

我在故事板中分配给UIButtons的类。
为什么这些属性在PLButton和PLEventButton中都不起作用(它们为零)?

故事板中的对象是initWithCoder方法初始化的。 因此,只需在中调用您的初始化方法

 - (id)initWithCoder:(NSCoder*)aDecoder 
{
    self = [super initWithCoder:aDecoder];
    if (self)
    {
        [self myInitialization];
    }

    return self;
}