iOS-圆角和边框共存

释放双眼,带上耳机,听听看~!

圆角和边框共存

CGRect rect = CGRectMake(10, 100, 300, 200);
    UIView * view = [[UIView alloc] initWithFrame:rect];
    view.backgroundColor = [UIColor grayColor];
//    view.layer.borderWidth = 1;
//    view.layer.borderColor = [UIColor greenColor].CGColor;
    [self.view addSubview:view];

    UIBezierPath *rounded = [UIBezierPath bezierPathWithRoundedRect:view.bounds byRoundingCorners:(UIRectCornerTopRight | UIRectCornerTopLeft) cornerRadii:CGSizeMake(5, 5)];
    CAShapeLayer *shapLayer = [[CAShapeLayer alloc] init];
    [shapLayer setPath:rounded.CGPath];
    view.layer.mask = shapLayer;
    
    CAShapeLayer *borderLayer = [CAShapeLayer layer];
    borderLayer.frame = view.bounds;
    borderLayer.lineWidth = 1.5f;
    borderLayer.strokeColor = [UIColor  redColor].CGColor;
    borderLayer.fillColor = [UIColor clearColor].CGColor;
    borderLayer.path = rounded.CGPath;

    [view.layer insertSublayer:borderLayer atIndex:0];

 

人已赞赏
iOS文章

iOS-多个Cocoapods如何共存并自由切换?

2019-9-25 16:12:22

iOS文章

iOS 中的各种锁

2019-9-25 17:28:18

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
有新消息 消息中心
搜索