iOS开发-使用UIBezierPath剪切视图圆角

注:直接调用下面的方法即可,但是下面的方法必须在视图完成了布局之后再调用,否则将会看不到被剪切的视图!!!

Swift版本:

fileprivate func cutCircularBeadMethod(view:UIView,roundingCorners:UIRectCorner,cornerRadii:CGSize) {
    let maskPath = UIBezierPath(roundedRect: view.bounds, byRoundingCorners: roundingCorners, cornerRadii: cornerRadii)
    let maskLayer = CAShapeLayer()
    maskLayer.frame = view.bounds
    maskLayer.path = maskPath.cgPath
    view.layer.mask = maskLayer
}

OC版本:

-(void)changeLabelStyle:(UILabel*)label {
    UIBezierPath*maskPath = [UIBezierPathbezierPathWithRoundedRect:label.bounds byRoundingCorners:UIRectCornerTopRight | UIRectCornerBottomRightcornerRadii:CGSizeMake(20, 20)];
    CAShapeLayer*maskLayer = [[CAShapeLayeralloc] init];
    maskLayer.frame = label.bounds;
    maskLayer.path = maskPath.CGPath;
    label.layer.mask = maskLayer;
}

你可能感兴趣的:(iOS开发-使用UIBezierPath剪切视图圆角)