First I recommend not to generate the UIImage in the iOS app and send it to the Watch Extension because sending an image (ie. NSData
) is a lot more data than just sending the coordinates of graph points.
To draw the graph in a clear way I recommend to create a CGContext using UIGraphicsBeginImageContextWithOptions
with exactly the size you get from the contentFrame
property of WKInterfaceController
and a scale of 2 because the Watch display is always Retina. See this example:
CGSize size = self.contentFrame.size;
if (size.width > 150)
size.height = 99; // 42mm
else
size.height = 87; // 38mm
[self.graphImage setHeight:size.height];
DLog(@"drawing graph into size %@", NSStringFromCGSize(size));
UIGraphicsBeginImageContextWithOptions(size, NO, 2);
[graph drawRect:CGRectMake(0, 0, size.width, size.height)]; // draw something
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[self.graphImage setImage:image];
I am using this code with a glance so I need to have specific heights according to glance templates. I am setting the height of the WKInterfaceImage
manually to make sure it has the same size like the UIImage, to avoid scaling and thus dithering.
This seems to work but it's a bit dirty because of the fixed point numbers.
Note that the 42mm watch gives you a contentFrame
width of 156 points, while the 38mm gives you 136 points so you better take these widths from the contentFrame
in case it changes in a future WatchOS.