IOS中级篇 —— Autoresizing
UIView *blueView = [[UIView alloc] init];
[self.view addSubview:blueView];
blueView.backgroundColor = [UIColor blueColor];
blueView.backgroundColor = [UIColor blueColor];
blueView.center = self.view.center;
blueView.bounds = CGRectMake(0, 0, 150, 150);
self.blueView = blueView;
/*
Flexible 灵活的,自由的
typedef NS_OPTIONS(NSUInteger, UIViewAutoresizing) {
UIViewAutoresizingNone = 0,
UIViewAutoresizingFlexibleLeftMargin = 1 << 0,
// 左边是自由的,右边是固定的(与storyboard中相反)
UIViewAutoresizingFlexibleWidth = 1 << 1,
// 宽度是可拉伸的
UIViewAutoresizingFlexibleRightMargin = 1 << 2,
// 右边是自由的,左边是固定的(与storyboard中相反)
UIViewAutoresizingFlexibleTopMargin = 1 << 3,
// 顶部是自由的,底部是固定的(与storyboard中相反)
UIViewAutoresizingFlexibleHeight = 1 << 4,
// 高度是自由的(高度是可拉伸的)
UIViewAutoresizingFlexibleBottomMargin = 1 << 5
// 底部是自由的,顶部是固定的(与storyboard中相反)
};
*/
// 四周固定,中间灵活
// redView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
// 四周灵活,中间固定
// 多个通过 "|" 进行连接
blueView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleBottomMargin;