自动布局 autoresizingMask属性的使用( UIViewAutoresizing)
遇到这样的代码_locationButton.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin;
不是特别的理解做以下的资料补充:
UIView中有个属性是autoresizingMask,该属性是用来控制控件的自适应。
UIViewAutoresizing是一个枚举类型,默认是UIViewAutoresizingNone,也就是不做任何处理。
1 typedef NS_OPTIONS(NSUInteger, UIViewAutoresizing) { 2 UIViewAutoresizingNone = 0, 3 UIViewAutoresizingFlexibleLeftMargin = 1 << 0, 4 UIViewAutoresizingFlexibleWidth = 1 << 1, 5 UIViewAutoresizingFlexibleRightMargin = 1 << 2, 6 UIViewAutoresizingFlexibleTopMargin = 1 << 3, 7 UIViewAutoresizingFlexibleHeight = 1 << 4, 8 UIViewAutoresizingFlexibleBottomMargin = 1 << 5 9 };
UIViewAutoresizingNone |
不会随父视图的改变而改变 |
UIViewAutoresizingFlexibleLeftMargin |
自动调整view与父视图左边距,以保证右边距不变 |
UIViewAutoresizingFlexibleWidth |
自动调整view的宽度,保证左边距和右边距不变 |
UIViewAutoresizingFlexibleRightMargin |
自动调整view与父视图右边距,以保证左边距不变 |
UIViewAutoresizingFlexibleTopMargin |
自动调整view与父视图上边距,以保证下边距不变 |
UIViewAutoresizingFlexibleHeight |
自动调整view的高度,以保证上边距和下边距不变 |
UIViewAutoresizingFlexibleBottomMargin |
自动调整view与父视图的下边距,以保证上边距不变 |
UIViewAutoresizingNone:控件相对于父视图坐标值不变;
UIViewAutoresizingFlexibleWidth:控件的宽度随着父视图的宽度按比例改变;
例如:label宽度为100,屏幕的宽度为320。当屏幕宽度为480时,label宽度变为100*480/320
UIViewAutoresizingFlexibleHeight:与UIViewAutoresizingFlexibleWidth相同
UIViewAutoresizingFlexibleLeftMargin:到屏幕左边的距离随着父视图的宽度按比例改变;
例如:CGRectMake(50, 100, 200, 40)]; 当屏幕的宽度为320,x为50;当屏幕宽度为480时,labelx坐标变为 50*480/320。
控件坐标变为 CGRectMake(75, 100, 200, 40)];
感谢您的访问!
若对您有帮助或有兴趣请关注博客:http://www.cnblogs.com/Rong-Shengcom/