Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.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
Xcode 如何绕过工作界面图像';在;手表应用程序?_Xcode_Imageview_Watchkit_Apple Watch - Fatal编程技术网

Xcode 如何绕过工作界面图像';在;手表应用程序?

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

有很多 观看具有圆角的应用程序。我试图在我的测试应用程序中绕过一些WKInterfaceImages,但我不明白如何做到这一点

我无法使用imageView.layer。。。和普通的iPhone应用程序一样,我找不到其他方法来使用代码或故事板


我必须屏蔽所有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的。不管怎样,我很高兴听到你解决了你的问题!是的,我的这是个骗局!如果有人能为我的问题找到真正的解决方案,我会继续回答这个问题。