swift画线

    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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 【Aipm引导页】 https://58976235.wodemo.net/down/20170514/44034...
    Mr_洛寒阅读 2,721评论 3 5
  • 我记得那美妙的瞬间, 你就在我的眼前降临, 如同昙花一现的梦幻, 如同纯真之美的化身。一《致克恩》 这不应只是普希...
    Maintain阅读 437评论 0 1
  • 晚上19:30分与五哥在地下停车场一起散步并请教商业模式和股全分配,五哥对模模式给于肯定给出建议:1、股东必须交纳...
    陈诚chen阅读 214评论 0 2
  • 感恩终于有一个周末可以很好的睡一个懒觉,太舒服啦,在连续上了两个星期的情况下休息一天,美美的睡一觉,感觉好轻松!...
    记忆法演讲教练娇娇阅读 119评论 0 0