Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/105.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在代码中创建图像并将其显示在UIImageView中_Ios_Swift_Cocoa Touch - Fatal编程技术网

Ios 在代码中创建图像并将其显示在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

我试图创造一个形象。通过检查大小,我可以看到图像已创建。但我无法将该图像指定为UIImageView的图像属性。请帮忙

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()