iOS View添加边框及圆角

//

//  ViewController.m

//  边框测试

//

#import "ViewController.h"

@interface ViewController ()

@property (weak, nonatomic) IBOutlet UIImageView *imageView;

@property (weak, nonatomic) IBOutlet UIButton *button;

@end

@implementation ViewController

- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view.

    self.imageView.layer.borderWidth = 1;//设置边框大小

    self.imageView.layer.borderColor = [UIColor redColor].CGColor;//设置边框颜色

    [self.imageView.layer setCornerRadius:10];//设置四个叫都为圆角10


    self.button.layer.borderWidth = 1;//设置边框大小

    self.button.layer.borderColor = [UIColor redColor].CGColor;//设置边框颜色

    self.button.layer.masksToBounds = YES;//是否遮罩边界

    CGFloatradius = 10;// 圆角大小

    UIRectCorner corner = UIRectCornerBottomLeft | UIRectCornerTopRight; // 圆角位置

    UIBezierPath * path = [UIBezierPath bezierPathWithRoundedRect:self.button.bounds byRoundingCorners:corner cornerRadii:CGSizeMake(radius, radius)];

    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];

    maskLayer.frame=self.button.bounds;

    maskLayer.path= path.CGPath;

    self.button.layer.mask= maskLayer;

}

@end

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容