swift画线

作者: 格调main | 来源:发表于2016-09-14 09:45 被阅读715次
    override func drawRect(rect: CGRect) {
        super.drawRect(rect)
        let context = UIGraphicsGetCurrentContext()
        CGContextSetLineCap(context,CGLineCap.Round)//
        CGContextSetLineWidth(context, 2)// 线宽
        CGContextSetAllowsAntialiasing(context, true)// 锯齿
        CGContextSetRGBStrokeColor(context, 231/255, 231/255, 231/255, 1)//颜色
        CGContextBeginPath(context)
        CGContextMoveToPoint(context, 0, 0)// 起点坐标
        CGContextAddLineToPoint(context, self.frame.width, 0)// 终点坐标
        CGContextStrokePath(context)
    }

oc 方法

- (void)drawRect:(CGRect)rect {
    
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetLineCap(context, kCGLineCapRound);
    CGContextSetLineWidth(context, 3);  //线宽
    CGContextSetAllowsAntialiasing(context, true);
    CGContextSetRGBStrokeColor(context, 0.0 / 255.0, 0.0 / 255.0, 0.0 / 0.0, 1.0);  //线的颜色
    CGContextBeginPath(context);
    
    CGContextMoveToPoint(context, 0, 0);  //起点坐标
    CGContextAddLineToPoint(context, self.frame.size.width, self.frame.size.height);   //终点坐标
    
    CGContextStrokePath(context);
}

注: UItableView cell 上划线会被 contentView 背景遮住 需要让他得背景透明

博客 文章地址http://chenzhao.date/2016/09/11/ios%E7%94%BB%E7%BA%BF.html

相关文章

  • swift画线

    oc 方法 注: UItableView cell 上划线会被 contentView 背景遮住 需要让他得背景透...

  • iOS swift 画线

    需要继承UIView 重写draw 方法 //自定义View

  • 基础绘制

    1.基础画线OC: swift: 2.画弧线OC Swift 3.画圆(椭圆)OC Swift 4.画弧OC Sw...

  • Swift--UIBezierPath和CAShapeLayer

    UIBezierPath和CAShapeLayer画线 (注意:该文章仅对Swift语言的画图部分的学习做简单总结...

  • Swift 画线控件(支持xib和storyboard)

    因项目中经常用到各种分割线,索性封装了一个画线的控件。 [github] 路径 特性 支持在xib中使用 支持设置...

  • 画线

    看着马路上为规范车辆行驶而画出的线,我有一瞬间感觉自己被某种潜在的恶意所束缚。 看着前排车辆突然亮起的红色尾灯,我...

  • 画线

    使用CAShapeLayer和UIBezierPath在UIView上画线。

  • 画线

    http://www.cnblogs.com/ygm900/archive/2013/07/02/3167334....

  • 画线

    如何为你的UIView添加边缘分割线 相遇相识相恋相濡以末5楼 · 2016.04.15 15:31 为什么要用r...

  • libGdx使用mesh画线

    使用mesh画线,并贴上纹理。画线类 控制顶点 效果:

网友评论

    本文标题:swift画线

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