当我尝试在watchOS应用程序中使用UIGraphicsImageRenderer时,编译器抛出一个错误。entry in the documentation看起来只在iOS和tvOS中可用。你知道为什么会这样吗?
import WatchKit
struct ImageGenerator() {
func image() -> UIImage {
let format = UIGraphicsImageRendererFormat() // ERROR
format.scale = 1
format.opaque = true
let renderer = UIGraphicsImageRenderer(size: size, format: format) // ERROR
let image = renderer.image { imageRendererContext in
// ...
}
}
}发布于 2017-01-19 15:10:55
watchOS上不提供UIGraphicsImageRenderer。但是,您仍然可以在watchOS上使用传统呈现API:
func image() -> UIImage {
UIGraphicsBeginImageContextWithOptions(yourImageSize, isOpaque, scale)
defer { UIGraphicsEndImageContext() }
let context = UIGraphicsGetCurrentContext()!
// draw your image at here...
return UIGraphicsGetImageFromCurrentImageContext()! // get image
}https://stackoverflow.com/questions/38811333
复制相似问题