ios – 用UIBezierPath画一条线

ios – 用UIBezierPath画一条线,第1张

概述首先使用BezierPaths,想知道这个功能是如何实际应用的.目前,贝塞尔路径在图像的框架内移动,而不是在屏幕上绘制. 有更好的方法吗? func drawLineFromPoint(start : CGPoint, toPoint end:CGPoint, ofColor lineColor: UIColor, inView view:UIView) { var maxWidth = 首先使用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 subvIEw    var image = UIGraphicsGetimageFromCurrentimageContext()    var imageVIEw = UIImageVIEw(image: image)    vIEw.addSubvIEw(imageVIEw)    UIGraphicsEndImageContext()}
解决方法 结束这样做:
func drawlineFromPoint(start : CGPoint,inVIEw vIEw:UIVIEw) {    //design the path    var path = UIBezIErPath()    path.movetoPoint(start)    path.addlinetoPoint(end)    //design path in layer    var shapeLayer = CAShapeLayer()    shapeLayer.path = path.CGPath    shapeLayer.strokecolor = linecolor.CGcolor    shapeLayer.linewidth = 1.0    vIEw.layer.addSublayer(shapeLayer)}
总结

以上是内存溢出为你收集整理的ios – 用UIBezierPath画一条线全部内容,希望文章能够帮你解决ios – 用UIBezierPath画一条线所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1113064.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存