UIGraphicsBeginImageContext(mapVIEw.bounds.size) let context : CGContext = UIGraphicsGetCurrentContext()! context.addlines(between: [CGPoint(x:oldX,y:oldY),CGPoint(x:newX,y:newY)]) context.setstrokecolorSpace(CGcolorSpaceCreateDeviceRGB()) context.setstrokecolor(UIcolor.blue.cgcolor.components!) context.setlinewidth(3) mapVIEw?.image?.draw(at: CGPoint(x:0,y:0)) context.strokePath() mapVIEw.image = UIGraphicsGetimageFromCurrentimageContext()! UIGraphicsEndImageContext()解决方法 一种选择是在图像视图中添加子视图,并将线条绘制代码添加到其绘图(_ rect:CGRect)方法中.
示例游乐场实施:
class lineVIEw : UIVIEw { overrIDe init(frame: CGRect) { super.init(frame: frame) self.backgroundcolor = UIcolor.init(white: 0.0,Alpha: 0.0) } required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } overrIDe func draw(_ rect: CGRect) { if let context = UIGraphicsGetCurrentContext() { context.setstrokecolor(UIcolor.blue.cgcolor) context.setlinewidth(3) context.beginPath() context.move(to: CGPoint(x: 5.0,y: 5.0)) // This would be oldX,oldY context.addline(to: CGPoint(x: 50.0,y: 50.0)) // This would be newX,newY context.strokePath() } }}let imageVIEw = UIImageVIEw(image: #imageliteral(resourcename: "image.png")) // This would be your mapVIEw,here I am just using a random imagelet lineVIEw = lineVIEw(frame: imageVIEw.frame)imageVIEw.addSubvIEw(lineVIEw)总结
以上是内存溢出为你收集整理的如何在swift 3中的图像上的两点之间画一条线?全部内容,希望文章能够帮你解决如何在swift 3中的图像上的两点之间画一条线?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)