zoukankan      html  css  js  c++  java
  • iOS开发设置view某几个角为圆角

    我们知道设置四个角都为圆角很简单,创建一个view,设置其layer.cornerRadius即可,代码如下:
        UIView *testview = [[UIView alloc] init];
        testview.layer.cornerRadius = 10;
        [self.view addSubview: testview];
    其实指定圆角也是通过view的layer属性来设置的,我通过设置控件的上面两个角为圆角来举例,代码如下:
     
     UIView *testview = [[UIView alloc] init];
        [self.view addSubview: testview];
    
        UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect: testview.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(10,10)];
        //创建 layer
        CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
        maskLayer.frame = testview.bounds;
        //赋值
        maskLayer.path = maskPath.CGPath;
        testview.layer.mask = maskLayer;
    首先创建view,然后单独设置其layer的方法,再将其赋值给view的layer属性即可,通过方法里面的参数UIRectCornerTopLeft,UIRectCornerTopRight我们便可以看出这是设置其左上角以及右上角为圆角,在cornerRadii:中设置圆角尺寸即可实现我们想要的效果。
  • 相关阅读:
    2015 多校联赛 ——HDU5389(dp)
    spring MVC配置详解
    面试题整理11
    面试题整理09
    Spring和SpringMVC的区别
    SpringMVC01
    js中typeof与instanceof用法小记
    Java 可变参数
    log4j文件的配置
    Hibernate 分组查询 子查询 原生SQL
  • 原文地址:https://www.cnblogs.com/-yun/p/12133495.html
Copyright © 2011-2022 走看看