#import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; UIView *view = [[UIView alloc]initWithFrame:CGRectMake(100, 100, 200, 200)]; view.backgroundColor = [UIColor colorWithRed:0 green:1 blue:1 alpha:0.8]; [self.view addSubview:view]; //autoresizingMask view.autoresizingMask = UIViewAutoresizingFlexibleWidth; // UIViewAutoresizingNone = 0,不進行自動調整 // UIViewAutoresizingFlexibleLeftMargin = 1 << 0,自動調整與superview左側距離,右側距離保持不變 // UIViewAutoresizingFlexibleWidth = 1 << 1,自動調整寬度,保證與superview左右距離不變 // UIViewAutoresizingFlexibleRightMargin = 1 << 2,自動調整與superview右側距離,左側距離保持不變 // UIViewAutoresizingFlexibleTopMargin = 1 << 3,頂部柔軟,底部固定 // UIViewAutoresizingFlexibleHeight = 1 << 4,自動調整高度,保證與superview上下距離不變 // UIViewAutoresizingFlexibleBottomMargin = 1 << 5底部柔軟,頂部固定 } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end