通过代码设置 WKInterfaceImage 的(边界)半径

Set (border) radius of a WKInterfaceImage by code

我必须通过 Swift 代码设置 WKInterfaceImage 的半径属性。

我需要与其他 UIImageView 相同的格式:

logoView.layer.cornerRadius = logoView.frame.width / 2
    logoView.clipsToBounds = true
    logoView.layer.borderWidth = 1.0
    logoView.layer.borderColor = UIColor (
                                    red: 0x33 / 255,
                                    green: 0x99 / 255,
                                    blue: 0x66 / 255,
                                    alpha: 1.0
                                ).CGColor

我查看了参考指南,但没有找到解决方案。感谢您的帮助!

您没有 WKInterfaceImage 的此类功能。只有少数 public 个 API。

为了在 WatchKit 中对界面元素进行圆角处理,您需要使用 WKInterfaceGroup。它允许您直接在故事板中修改所有角的半径。

如果您需要在组周围创建轮廓边框,则需要创建自定义 UIImage 并将其设置为组的背景图像。

没有直接的方法可以做到这一点。但我可以想到一个解决方法。唯一可以具有圆角半径的界面对象是 WKInterfaceGroup。所以,你可以把一个组放在一个组中,并给两个角半径。将您的图像设置为组内背景。

要设置边框宽度和颜色,请为内部组指定相对于外部组的宽度和高度。并给外部一个你想要的边框颜色的背景。


Just set the Radius Property and remember group should not be nested otherwise corners will not set to 0