有更好的方法吗?
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画一条线所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)