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];
  • 如有问题可添加QQ群:234812704
  • 欢迎各位一块学习,提高逼格!
  • 也可以添加洲洲哥的微信公众号

可以来微信公众号(洲洲哥)后台给我留言。 快来扫码关注我们吧!

iOS-圆角和边框共存_第1张图片
公众号二维码

你可能感兴趣的:(iOS-圆角和边框共存)