美文网首页
iOS开发中为视图添加指定个数边框

iOS开发中为视图添加指定个数边框

作者: 蛋哥是只猫 | 来源:发表于2017-03-21 17:56 被阅读0次
    - (UIView *)borderForView:(UIView *)originalView color:(UIColor *)color{
        UIBezierPath * bezierPath = [UIBezierPath bezierPath];
       
        [bezierPath moveToPoint:CGPointMake(0,originalView.frame.size.height)];
    
        [bezierPath addLineToPoint:CGPointMake(0, 0)];
        
        [bezierPath addLineToPoint:CGPointMake(originalView.frame.size.width, 0)];
        
        [bezierPath addLineToPoint:CGPointMake( originalView.frame.size.width, originalView.frame.size.height)];
        
        CAShapeLayer * shapeLayer = [CAShapeLayer layer];
        
        shapeLayer.strokeColor = color.CGColor;
        
        shapeLayer.fillColor  = [UIColor clearColor].CGColor;
        
        shapeLayer.path = bezierPath.CGPath;
        
        shapeLayer.lineWidth = 1.0f;
        
        [originalView.layer addSublayer:shapeLayer];
    
        return originalView;
    }
    

    效果图:

    图片.png

    相关文章

      网友评论

          本文标题:iOS开发中为视图添加指定个数边框

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