#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
UIView * view1=[[UIView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];
view1.backgroundColor=[UIColor orangeColor];
view1.tag=10;
[self.view addSubview:view1];
//激活停靠模式
//view1.autoresizesSubviews=YES;
//设置停靠模式的参数
UIView * view2=[[UIView alloc]initWithFrame:CGRectMake(20, 20, 60, 60)];
view2.backgroundColor=[UIColor blueColor];
[view1 addSubview:view2];
//激活停靠模式
view2.autoresizesSubviews=YES;
//设置停靠模式的参数
//UIViewAutoresizingFlexibleLeftMargin 停靠在右边,距离父视图右边距离不变化
//UIViewAutoresizingFlexibleWidth 宽度自适应,随着父试图的变化而变化
[view2 setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];
UIButton * btn=[UIButton buttonWithType:UIButtonTypeCustom];
btn.frame=CGRectMake(50, 400, 200, 100);
[btn setTitle:@"停靠模式变大" forState:UIControlStateNormal];
[btn setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
[self.view addSubview:btn];
[btn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
}
-(void)btnAction:(UIButton*)sender
{
//用标记获取view1的tag值
UIView * view1=[self.view viewWithTag:10];
//获取当前view1的大小
view1.frame=CGRectMake(view1.frame.origin.x, view1.frame.origin.y, view1.frame.size.width+10, view1.frame.size.height+10);
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end