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:中设置圆角尺寸即可实现我们想要的效果。
  • 相关阅读:
    Pycharm 2016 注册码
    在mac上搭建python环境
    Carthage 的使用
    生成唯一的随机字符串
    utf-8 转码--网址转码
    让自己的项目支持 Carthage
    系统自带的语音合成
    个性化 UIAlertController
    cocoaPods 创建自己的依赖库
    appleDoc 使用
  • 原文地址:https://www.cnblogs.com/-yun/p/12133495.html
Copyright © 2011-2022 走看看