在我们设置一些公用的UIView的时候使用XIB创建View的时候会发现有时候frame没法改变。解决方法: 重写drawRect方法: _myframe定义在.m文件中 - (instancetype)initWithFrame:(CGRect)frame{ self = [super initWithFrame:frame]; if (self) { NSArray *nibs=[[NSBundle mainBundle]loadNibNamed:@"ThirdLoginView" owner:nil options:nil]; self = [nibs objectAtIndex:0]; _myframe = frame; } return self; } -(void)drawRect:(CGRect)rect{ self.frame = _myframe; } |
|
来自: LoveSeasonLee > 《待分类》