UIView与transform

    /***********UIView位置及大小*************/
    UIView *view = [[UIView alloc]init];
    //1、frame设置位置及大小
//    view.frame = CGRectMake(100, 100, 100, 100);
    //2、center和bounds组合的方式
    //center是view自己的中心点
    view.center = CGPointMake(100 + 100/2, 40 + 100/2);
    //bounds的后两个参数是view自己的宽和高
    //bounds的前两个参数影响的是view本身坐标系圆点的位置
    //bounds的前两个参数大于0时:圆点坐标向左和向上移动;bounds的前两个参数小于0时:圆点坐标向右和向下移动
    //bounds的前两个参数为了不影响它上面子视图的位置,以后就可以写0,0
    view.bounds = CGRectMake(0, 0, 100, 100);
    //属性
    view.backgroundColor = [UIColor redColor];
    [self.view addSubview:view];
   
    UIView *view1 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 50, 50)];
    view1.backgroundColor = [UIColor grayColor];
    [view addSubview:view1];
   
    /***********UIView的变形属性****************/
    UIView *view2 = [[UIView alloc]initWithFrame:CGRectMake(100, 200, 200, 100)];
    view2.backgroundColor = [UIColor cyanColor];
   
    //变形属性:transform
    //以中心点为变形,中心点不变
    //大小变形:CGAffineTransformMakeScale
    //第一个参数影响的是宽:原本的宽*变形参数
    //第二个参数影响的是高:原本的高*变形参数
    view2.transform = CGAffineTransformMakeScale(0.5, 2);
    //角度变形:整数:顺时针转;负数:逆时针转
//    M_PI   180度
//    M_PI_2
    view2.transform = CGAffineTransformMakeRotation(M_PI_2/2);
   
    [self.view addSubview:view2];
   
    /************UIView-圆角****************/
    UIView *view3 = [[UIView alloc]initWithFrame:CGRectMake(50, 340, 100, 100)];
    view3.backgroundColor = [UIColor greenColor];
    //圆角:layer
    //圆角角度:cornerRadius  圆是正方形边长的一边
    view3.layer.cornerRadius = 20.0;
    //边框的宽度:borderWidth 默认0
    view3.layer.borderWidth = 3.0;
    //边框颜色:borderColor  默认黑色  赋值方式:[UIColor someColor].CGColor
    view3.layer.borderColor = [UIColor redColor].CGColor;
    //切割子视图超出父视图边框的属性:masksToBounds   默认为 NO  YES:切割  NO:不切割
    view3.layer.masksToBounds = NO;
    //只有当masksToBounds为NO阴影效果才能出来
    //阴影效果
    //阴影透明度:shadowOpacity  默认完全透明
    view3.layer.shadowOpacity = 1.0;
    //阴影的偏移量:shadowOffset  以本身view的(0,0)点偏移
    view3.layer.shadowOffset = CGSizeMake(100, 0);
    //阴影的颜色:shadowColor  默认黑色  赋值方式:[UIColor someColor].CGColor
    view3.layer.shadowColor = [UIColor redColor].CGColor;
    //阴影的圆角:shadowRadius   带有虚化效果
    view3.layer.shadowRadius = 40.0;
   
    [self.view addSubview:view3];
   
//    UIView *view4 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 50, 50)];
//    view4.backgroundColor = [UIColor orangeColor];
//    [view3 addSubview:view4]

 

posted @ 2015-08-24 11:38  谢涵..Fting!  阅读(357)  评论(0编辑  收藏  举报