Xcode 如何绕过工作界面图像';在;手表应用程序?
有很多 观看具有圆角的应用程序。我试图在我的测试应用程序中绕过一些WKInterfaceImages,但我不明白如何做到这一点 我无法使用imageView.layer。。。和普通的iPhone应用程序一样,我找不到其他方法来使用代码或故事板Xcode 如何绕过工作界面图像';在;手表应用程序?,xcode,imageview,watchkit,apple-watch,Xcode,Imageview,Watchkit,Apple Watch,有很多 观看具有圆角的应用程序。我试图在我的测试应用程序中绕过一些WKInterfaceImages,但我不明白如何做到这一点 我无法使用imageView.layer。。。和普通的iPhone应用程序一样,我找不到其他方法来使用代码或故事板 我必须屏蔽所有PNG还是有更简单的方法?你说得对CALayer和UIView在watchOS 2上不直接可用。但你们能够使用图形功能,例如,在手表上是完全可以接受的 Swift中的类似物: class ImageTools { class fun
我必须屏蔽所有PNG还是有更简单的方法?你说得对
CALayer
和UIView
在watchOS 2上不直接可用。但你们能够使用图形功能,例如,在手表上是完全可以接受的
Swift中的类似物:
class ImageTools {
class func imageWithRoundedCornerSize(cornerRadius:CGFloat, usingImage original: UIImage) -> UIImage {
let frame = CGRectMake(0, 0, original.size.width, original.size.height)
// Begin a new image that will be the new image with the rounded corners
UIGraphicsBeginImageContextWithOptions(original.size, false, 1.0)
// Add a clip before drawing anything, in the shape of an rounded rect
UIBezierPath(roundedRect: frame, cornerRadius: cornerRadius).addClip()
// Draw the new image
original.drawInRect(frame)
// Get the new image
let roundedImage = UIGraphicsGetImageFromCurrentImageContext()
// Lets forget about that we were drawing
UIGraphicsEndImageContext()
return roundedImage
}
}
在您的WKInterfaceController
类中的某个地方:
let originalImage = UIImage(named: "original-image")!
let roundedImage = ImageTools.imageWithRoundedCornerSize(60, usingImage: originalImage)
// Set `UIImage` for your `WKInterfaceImage`
imageOutlet.setImage(roundedImage)
我解决了从故事板中删除WKInterfaceImage,然后将其替换为WKInterfaceGroup的问题,我将其设置为与前一张图像相同的大小。然后,从属性检查器中,我设置了其半径(是的,可以使用组!)然后我在controller中声明了group,并使用
row.flagView.setBackgroundImageNamed(imageName)
@Matte.Car设置了图像-我用更合适的Watch示例更新了链接。它甚至可以工作,但它在Objective-C中。。。我试着翻译它,但我不能…。@Matte.Car-在Swift中添加了这个例子。它工作得很好。哇!我正在尝试测试它,但我无法理解为什么,使用row.flagView.setImageNamed(codice)
效果很好,但是使用let-immagine=UIImage(named:codice)代码>返回一个零值…这是一个完全不同的问题-尝试清理缓存或其他东西。事实上我知道:)但我认为问题是关于WKEIMAGE的。不管怎样,我很高兴听到你解决了你的问题!是的,我的这是个骗局!如果有人能为我的问题找到真正的解决方案,我会继续回答这个问题。