我想在我的视图上画一条细线,如我链接的图像所示

时间:2015-10-21 12:44:23

标签: swift line

http://i60.tinypic.com/o7826u.png

http://i59.tinypic.com/2s139kl.png

图像解释了我想要的东西和我得到的东西。这是我的代码。

func drawLineFromPoint(start : CGPoint, 
    toPoint end:CGPoint, 
    ofColor lineColor: UIColor, 
    inView view:UIView) {
     let path = UIBezierPath() 
     path.moveToPoint(start) 
     path.addLineToPoint(end) 
     //design path in layer 
     let shapeLayer = CAShapeLayer() 
     shapeLayer.path = path.CGPath 
     shapeLayer.strokeColor = lineColor.CGColor 
     shapeLayer.lineWidth = 0.22 
     view.layer.addSublayer(shapeLayer) 
    }

1 个答案:

答案 0 :(得分:1)

let lineView : UIView = UIView(frame: CGRect(0, 20, self.view.width, 2)
lineView.backgroundColor = UIColor.blackColor.colorWithAlphaComponent(0.2)