enum {
UIViewAutoresizingNone = 0,
UIViewAutoresizingFlexibleLeftMargin = 1 << 0,
UIViewAutoresizingFlexibleWidth = 1 << 1,
UIViewAutoresizingFlexibleRightMargin = 1 << 2,
UIViewAutoresizingFlexibleTopMargin = 1 << 3,
UIViewAutoresizingFlexibleHeight = 1 << 4,
UIViewAutoresizingFlexibleBottomMargin = 1 << 5
};
typedef NSUInteger UIViewAutoresizing;
UIViewAutoresizingNone 默认是None,也就是当父视图的大小变动时,设置的子view不做任何适应操作
UIViewAutoresizingFlexibleLeftMargin 视图靠右对齐
UIViewAutoresizingFlexibleWidth 视图自适应宽度
UIViewAutoresizingFlexibleRightMargin 视图靠左对齐
UIViewAutoresizingFlexibleTopMargin 视图靠下对齐
UIViewAutoresizingFlexibleHeight 视图自适应高度
UIViewAutoresizingFlexibleBottomMargin 视图靠上对齐
注意:LeftMargin、RightMargin、TopMargin、BottomMargin的实际对齐方向是相反的
示例:让按钮始终在 ViewController 的右上角显示:
- (void)viewDidLoad
{
[super viewDidLoad];
UIButton *right = [UIButton buttonWithType:UIButtonTypeRoundedRect];
right.frame = CGRectMake(self.view.frame.size.width-300, 0, 300, 300);
right.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[right setTitle:@"456" forState:UIControlStateNormal];
[self.view addSubview:right];
}