iOS中的UIView

UIView

UIView的位置

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //新建三个View界面(顺序是:红在底,蓝在中,黄在上)
    UIView *view1 = [[UIView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];
    view1.backgroundColor = [UIColor redColor];
    [self.view addSubview:view1];
    
    UIView *view2 = [[UIView alloc]initWithFrame:CGRectMake(120, 120, 100, 100)];
    view2.backgroundColor = [UIColor blueColor];
    [self.view addSubview:view2];
    
    UIView *view3 = [[UIView alloc]initWithFrame:CGRectMake(140, 140, 100, 100)];
    view3.backgroundColor = [UIColor yellowColor];
    [self.view addSubview:view3];
    
    //把视图放在最前面
    [self.view bringSubviewToFront:view1];
    
    //把视图放在最后面
    [self.view sendSubviewToBack:view1];
    
    //插入视图在。。。。。。之上
    [self.view insertSubview:view2 aboveSubview:view3];
    
    //插入视图在。。。。。。之下
    [self.view insertSubview:view2 belowSubview:view3];
    
    //按照位置插入视图(这三个视图最底下是2,中间是3,上面是4)
    [self.view insertSubview:view1 atIndex:4];

    
}



UIView的移动、缩放等

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //新建一个View界面
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];
    //这里的tag相当于一个学号(或编号),如果程序里有很多view,编号是用来区分的
    view.tag = 10;
    view.backgroundColor = [UIColor redColor];
    [self.view addSubview:view];
    
    
    //新建一个Button,控制视图旋转,缩放等
    UIButton *myButton = [[UIButton alloc]initWithFrame:CGRectMake(100, 250, 100, 50)];
    myButton.backgroundColor = [UIColor blueColor];
    [myButton setTitle:@"点击" forState:UIControlStateNormal];
    [myButton addTarget:self action:@selector(haha:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:myButton];

    
}

//Button方法
-(void)haha:(id)a{
    //编号接受view
    UIView *view = [self.view viewWithTag:10];
    
    //view的放大缩小
    view.transform = CGAffineTransformScale(view.transform, 2, 2);
    
    //旋转,按照弧度值
    view.transform = CGAffineTransformRotate(view.transform, M_1_PI);
    
    //移动,(是移动了,不是移动到)
    view.transform = CGAffineTransformTranslate(view.transform, 50, 50);
    
    
}




转载于:https://my.oschina.net/LBBB/blog/655377

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值