0

I have a app which has an Apple Watch extension. I have a UIImageView in the Watch face and would like to have the image change depending on condition. I have tried this.

if ((battery > 30)&& (battery < 110) && (bat = 1)){
           UIImage *lightning = [UIImage imageNamed:@"jag2@2X.png"];
           [self.Jag setImage:lightning];
       }

I have put the jag@@2x.png in my watch asserts folder but when I call this it doesn't load no image appears. If I load it in IB it is ok any ideas?

user1114881
  • 731
  • 1
  • 12
  • 25
  • What is `Jag`? Which complication family are you using? Does `imageNamed:` actually return an image? – Paulw11 Feb 05 '21 at 04:18
  • Jag is the UIImage that is in the complications group at the bottom of my screen in the watch storyboard. @property (weak, nonatomic) IBOutlet WKInterfaceImage* Jag; I'm not sure if it returns an image or not. Apparently not since no image appears when I call it. That is my question. How do I programmatically load an image. I thought this was the way but it doesn't work. And ideas. – user1114881 Feb 05 '21 at 14:52
  • You can set a breakpoint and see if the image is loaded. If the image isn't loaded the probably your asset name isn't correct. Normally you wouldn't have the @2x.png; you just use the name of the asset in the xcasset catalog. The asset name would typically be something like "jag2". – Paulw11 Feb 05 '21 at 19:31
  • I am a it confused by your reference to the storyboard and an IBOutlet. You don't use storyboards to provide complication views. Your code needs to fill in the appropriate complication template. E.g. https://stackoverflow.com/questions/52526994/how-to-create-apple-watchos5-complication – Paulw11 Feb 05 '21 at 19:35

1 Answers1

0

So I got this working. I added the images to the assets.xcassett in the watch extension and then left off the @2x as Paulw11 suggested but I did need to leave the .png on to get it to work. Thanks Paul for pointing me in the correct direction.

user1114881
  • 731
  • 1
  • 12
  • 25