Apple Watch fragmentation
2015-03-02
How to handle the different screen sizes of the Apple Watch
The Apple Watch comes in two sizes, the 38 mm and the 42 mm. Unfortunately, these devices to not share the same resolution. This has consequences for you as a developer when you need to show images and don't want to resort to downsampling.
The Apple documentation is not fantastic at this point. However, this is easily achieved.
Here is one way of selecting a picture depending on the type of hardware the code is running on:
Prefix every picture file with '42_' and '38_', e.g:
Create a function that adds the appropriate prefix to the picture path for you:
func imageName(name: String) -> String {
var height = WKInterfaceDevice.currentDevice().screenBounds.height
if (height == 195.0) {
return ("42_\(name)")
} else {
return ("38_\(name)")
}
}
- Use the helper function when retrieving an image name:
button.setBackgroundImageNamed(imageName("monkey"))
Note that Xcode automatically removes the *@2x.png@ part of the image name for you.