Ios 在代码中创建图像并将其显示在UIImageView中
我试图创造一个形象。通过检查大小,我可以看到图像已创建。但我无法将该图像指定为UIImageView的图像属性。请帮忙Ios 在代码中创建图像并将其显示在UIImageView中,ios,swift,cocoa-touch,Ios,Swift,Cocoa Touch,我试图创造一个形象。通过检查大小,我可以看到图像已创建。但我无法将该图像指定为UIImageView的图像属性。请帮忙 let imageRenderer=UIGraphicsImageRenderer(size: self.view.bounds.size) book = imageRenderer.image { c in let ctx=c.cgContext ctx.setStrokeColor(UIColor.black.cgColor) ctx.setLine
let imageRenderer=UIGraphicsImageRenderer(size: self.view.bounds.size)
book = imageRenderer.image { c in
let ctx=c.cgContext
ctx.setStrokeColor(UIColor.black.cgColor)
ctx.setLineWidth(5)
let x=self.view.bounds.maxX
let y=self.view.bounds.maxY
ctx.move(to: CGPoint(x:x/16,y:x/8))
ctx.addLine(to: CGPoint(x: x/2, y: x/4))
ctx.addLine(to: CGPoint(x: x-x/16, y: x/8))
ctx.addLine(to:CGPoint(x: x-x/16, y: y-x/8))
ctx.addLine(to: CGPoint(x: x/2, y: y-x/16))
ctx.addLine(to: CGPoint(x: x/16, y: y-x/8))
ctx.closePath()
}
self.image.image = book!
您只需添加线条,但不为其绘制颜色 你可以打电话给他们
ctx.strokePath()
紧接着(封闭内部)
更多信息可以在这里阅读
您遇到了什么错误?请尝试设置
self.image.image=imageRenderer.image{…}
注意:UIGraphicsImageRenderer
仅提供10.0+无错误,只是图像未显示。我正在尝试iOS 11的代码谢谢您的帮助。
ctx.closePath()