IOS autoresizingMask

在程序中看到这样代码      self.autoresizingMask = UIViewAutoresizingFlexibleWidth;

在网上查了查,博主讲的比较清楚,此处做一个保留

UIView中有个属性是autoresizingMask,该属性是用来控制控件的自适应。

UIViewAutoresizingNone

UIViewAutoresizingFlexibleLeftMargin

UIViewAutoresizingFlexibleWidth

UIViewAutoresizingFlexibleRightMargin

UIViewAutoresizingFlexibleTopMargin

UIViewAutoresizingFlexibleHeight

UIViewAutoresizingFlexibleBottomMargin

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)];

UIViewAutoresizingFlexibleRightMargin

UIViewAutoresizingFlexibleTopMargin

UIViewAutoresizingFlexibleBottomMargin

UIViewAutoresizingFlexibleLeftMargin类似

推荐阅读更多精彩内容