Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我对 UIView 进行了子类化,并在其中具有一些属性,例如背景颜色。我在提供的函数中初始化了颜色,initWithFrame:frame但它不起作用。我也试过init了,但它也不起作用。那么我应该把初始化放在哪里?
initWithFrame:frame
init
我猜你正在使用 storybard 或 nib 来加载视图。在这种情况下,您应该覆盖 initWithCoder。
-(id)initWithCoder:(NSCoder *)aDecoder{ if ( self = [super initWithCoder:aDecoder]){ NSLog(@"cmd %@",NSStringFromSelector(_cmd)); self.backgroundColor = [UIColor blueColor]; } return self; }
希望这有帮助。