Search code examples
watchkit

using setBackgroundimageNamed displays wrong image


I have an animated timer ring which uses numbered images timer0.png to timer200.png in an asset catalog. If I use setBackgroundImageNamed("timer5") on a group, it displays timer50. I'm assuming it looks for images with numbers after the name you specify and uses that instead, even if you are not animating. How can I force it to display timer5? Perhaps naming it 005 instead would work?


Solution

  • This is a known issue. Basically, when you ask for "timer5", WatchKit looks for the first frame of "timer5" which would be "timer50" (i.e. the 0th frame of the timer5 animation). To work around the issue, you can use startAnimatingWithImagesInRange:duration:repeatCount: with a range of length 1 so that your "animation" starts and ends at the requested frame number.