下記のようなコードでXIBファイルからViewインスタンスを生成した場合、CustomViewの大きさを変更しても
XIBファイルで定義したViewの大きさは変わらなかった。(flexible height, widthを設定しているのに!)
@interface CustomView : UIView { @protected IBOutlet UIView *_contentsView; } @implementation CustomView // @Override - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { UINib *nib = [UINib nibWithNibName:@"CustomView" bundle:[NSBundle mainBundle]]; [nib instantiateWithOwner:self options:nil]; [self addSubview:_contentsView]; } return self; }
原因はXIBから生成したViewはすべて_contentsViewのSubviewになっているが、_contentsViewがflexible height,widthになっていなかったため。
コードから生成しているViewがあるとこういうことがあるからいやだなぁ。
できる限りViewの設定はXIBでやりたい。