iOS View添加圆角

1. view四个边角添加圆角方法

    self.m_headerImageView.layer.masksToBounds = YES;
    self.m_headerImageView.layer.cornerRadius = 10;
    self.m_headerImageView.layer.borderColor = [UIColor whiteColor].CGColor;
    self.m_headerImageView.layer.borderWidth = 2;

2. 自定义添加圆角,

注意:如果view使用autolayout会出问题。最好是用代码创建view.

- (void)addCorner:(UIRectCorner)corner andRadius:(CGFloat)radius
{
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:corner cornerRadii:CGSizeMake(radius, radius)];
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.frame = self.bounds;
    maskLayer.path = maskPath.CGPath;
    self.layer.mask = maskLayer;
}





你可能感兴趣的:(ios)