美文网首页
button设置一边圆角

button设置一边圆角

作者: 夜未殇 | 来源:发表于2017-05-02 20:05 被阅读0次

    设置一边圆角
    缺点:不能设置颜色,正在研究。

    typedef NS_ENUM(NSInteger, CNButtonSide) {
        CNButtonSideLeft,
        CNButtonSideRight,
        CNButtonSideUp,
        CNButtonSideDown
    };
    
    
    - (void)roundSide:(CNButtonSide)side
    {
        UIBezierPath *maskPath;
        
        if (side == CNButtonSideLeft)
            maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds
                                             byRoundingCorners:(UIRectCornerTopLeft|UIRectCornerBottomLeft)
                                                   cornerRadii:CGSizeMake(8.f, 8.f)];
        else if (side == CNButtonSideRight)
            maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds
                                             byRoundingCorners:(UIRectCornerTopRight|UIRectCornerBottomRight)
                                                   cornerRadii:CGSizeMake(8.f, 8.f)];
        else if (side == CNButtonSideUp)
            maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds
                                             byRoundingCorners:(UIRectCornerTopLeft|UIRectCornerTopRight)
                                                   cornerRadii:CGSizeMake(8.f, 8.f)];
        else
            maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds
                                             byRoundingCorners:(UIRectCornerBottomLeft|UIRectCornerBottomRight)
                                                   cornerRadii:CGSizeMake(8.f, 8.f)];
        
        // Create the shape layer and set its path
        CAShapeLayer *maskLayer = [CAShapeLayer layer];
        maskLayer.frame = self.bounds;
        maskLayer.path = maskPath.CGPath;
        
        // Set the newly created shape layer as the mask for the image view's layer
        self.layer.mask = maskLayer;
        
        [self.layer setMasksToBounds:YES];
    }
    

    相关文章

      网友评论

          本文标题:button设置一边圆角

          本文链接:https://www.haomeiwen.com/subject/vxdhtxtx.html