ストーリーボードの Viewcontroller に UIButton を追加しました。このボタンをサブクラス化し、アウトレットを ViewController に設定すると、public changeColor 関数で背景色を変更できます。
しかし、コンストラクターでこれを行いたいので、外部から行う必要はありません。デフォルトで呼び出されるコンストラクターを見つけようとしましたが、以下の例では出力が得られません。ストーリーボードにオブジェクトを追加するだけでデフォルトで呼び出されるコンストラクターはありますか?
- (id)initWithFrame:(CGRect)frame
{
NSLog(@"constructor");
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
-(id)init {
NSLog(@"constructor");
self = [super init];
if (self) {
// Initialization code
}
return self;
}
-(void)changeColor{
[self setBackgroundColor:[UIColor redColor]];
}