我可以在watchOS 3上使用带有WatchKit的UIGraphicsImageRenderer吗?

时间:2016-08-07 05:54:22

标签: swift core-graphics watchkit ios10 watch-os-3

当我尝试在watchOS应用程序中使用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 // ... } } } 时,编译器会抛出错误。 entry in the documentation看起来只在iOS和tvOS中可用。你知道为什么会这样吗?

ul {
    list-style-type: none;
    margin: 0;
    padding: 0;
}
nav{
	background-color: #000;
	text-align: center;
	padding: 8px;
}

nav li{
display: inline-block;
margin: 5px 40px 5px 40px;
padding: 3px;
font-size: 40px;
}
body{
	padding: 16px;
	margin: 10px;
	background-color: #FFE4C4;
}
nav li a{
	color: white;
	text-decoration: none;
	font-family: sans-serif;

1 个答案:

答案 0 :(得分:2)

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
}