相关疑难解决方法(0)

用UIBezierPath画一条线

第一次使用BezierPaths,想知道这个函数实际上应该如何实现.目前,贝塞尔曲线路径在图像的帧内移动,而不是在屏幕上绘制.

有没有更好的方法呢?

func drawLineFromPoint(start : CGPoint, toPoint end:CGPoint, ofColor lineColor: UIColor, inView view:UIView) {

    var maxWidth = abs(start.x - end.x)
    var maxHeight = abs(start.y - end.y)

    var contextSize : CGSize!
    if maxWidth == 0 {
        contextSize = CGSize(width: 1, height: maxHeight)
    }else {
        contextSize = CGSize(width: maxWidth, height: 1)
    }

    //design the path
    UIGraphicsBeginImageContextWithOptions(contextSize, false, 0)
    var path = UIBezierPath()
    path.lineWidth = 1.0
    lineColor.set()

    //draw the path and make visible
    path.moveToPoint(start)
    path.addLineToPoint(end)
    path.stroke()

    //create image from path and add to …
Run Code Online (Sandbox Code Playgroud)

ios uibezierpath swift

34
推荐指数
3
解决办法
3万
查看次数

标签 统计

ios ×1

swift ×1

uibezierpath ×1