layoutSubviews
@interface TwoView ()
@property (nonatomic,strong)UIView *twoView1;
@property (nonatomic,strong)UIView *twoView2;
@end
@implementation TwoView
- (instancetype)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
_twoView1 = [[UIView alloc] initWithFrame:CGRectMake(10, 10, 50, 50)];
_twoView1.backgroundColor = [UIColor redColor];
_twoView2 = [[UIView alloc] initWithFrame:CGRectMake(70, 10, 50, 50)];
_twoView2.backgroundColor = [UIColor redColor];
[self addSubview:_twoView2];
[self addSubview:_twoView1];
}
return self;
}
//如果initWithFrame中设置了子控件的frame layoutSubviews这个方法不写也可以.
//layoutSubviews这个方法是 重新布局子控件的Frame , 如果写了会以layoutSubviews里面的Frame为主
-(void)layoutSubviews{
[super layoutSubviews];
_twoView1.frame = CGRectMake(10, 10, 80, 50);
_twoView2.frame = CGRectMake(70, 10, 80, 50);
}
浙公网安备 33010602011771号