4

I have to set the radius attribute of a WKInterfaceImage by Swift code.

I need the same formatting as for my others UIImageViews:

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

I checked the reference guide but I found no solution. Thanks for you help!

3 Answers 3

15

You don't have this type of functionality with a WKInterfaceImage. There are only a few public APIs.

In order to round the corners of an interface element in WatchKit, you need to use a WKInterfaceGroup. It allows you to modify the radius of all the corners directly in the storyboard.

WKInterfaceGroup Parameters in Storyboard

If you need to create an outlined border around the group, then you'll need to create a custom UIImage and set it as the background image of the group.

2
  • Thanks for the idea! The problem is, that I have no idea how many pixels the radius should have (calculated by code-behind source) and the clipsToBounds attribute is missing. :(
    – Tobonaut
    Mar 8, 2015 at 21:48
  • 1
    Well, you have a few options. You could render the image manually using Core Graphics, or you could create a few different outline images using cap insets so scale up to the appropriate size. Without knowing more about your use case, that's about as much as I can help.
    – cnoon
    Mar 8, 2015 at 22:04
9

There is no direct way to do this. But I can think of a work around. The only interface object that can have a corner radius is WKInterfaceGroup. So, you can put a group inside a group and give both a corner radius. Set your image as the inner group background.

To have a border width & color, give your inner group a relative width and hight to the outer one. And give the outer a background of which you want your border color be.

1
  • That sounds logical. Thanks for the idea.
    – Tobonaut
    Mar 8, 2015 at 21:48
0

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


Just set the Radius Property and remember group should not be nested otherwise radius will not apply

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.