- UIViewAutoresizingFlexibleLeftMargin 距离父控件的左边是可以伸缩的
- UIViewAutoresizingFlexibleBottomMargin 距离父控件的底部是可以伸缩的
- UIViewAutoresizingFlexibleRightMargin 距离父控件的右边是可以伸缩的
- UIViewAutoresizingFlexibleTopMargin 距离父控件的顶部是可以伸缩的
- UIViewAutoresizingFlexibleHeight 高度跟随父控件的高度进行伸缩
- UIViewAutoresizingFlexibleWidth 宽度跟随父控件的宽度进行伸缩
#import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; UIView *redView = [[UIView alloc] init]; redView.backgroundColor = [UIColor redColor]; CGFloat redViewX = self.view.frame.size.width - 100; CGFloat redViewY = self.view.frame.size.height - 100; redView.frame = CGRectMake(redViewX, redViewY, 100, 100); /** UIViewAutoresizingFlexibleLeftMargin 距离父控件的左边是可以伸缩的 UIViewAutoresizingFlexibleBottomMargin 距离父控件的底部是可以伸缩的 UIViewAutoresizingFlexibleRightMargin 距离父控件的右边是可以伸缩的 UIViewAutoresizingFlexibleTopMargin 距离父控件的顶部是可以伸缩的 UIViewAutoresizingFlexibleHeight 高度跟随父控件的高度进行伸缩 UIViewAutoresizingFlexibleWidth 宽度跟随父控件的宽度进行伸缩 */ redView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleWidth; [self.view addSubview:redView]; } @end
竖屏效果:
横屏效果: