Muhammad Umar
Muhammad Umar

Reputation: 151

Apple Watch: how to show image in Glance

I am trying to show an image in Glance View. The image format is .png, and I have placed it in WatchKitApp bundle.

In Glance, I have added a WKInterfaceImage in default group presented in Glance.

below is my code to dynamically locate an image to it.

//
//  GlanceController.swift
//  Zappatap WatchKit Extension
//
//  Created by Muhammad Umar on 4/5/15.
//  Copyright (c) 2015 Zivato. All rights reserved.
//

import WatchKit
import Foundation


class GlanceController: WKInterfaceController {

    @IBOutlet weak var glanceLable: WKInterfaceLabel!

    @IBOutlet weak var glanceImage: WKInterfaceImage!

    override func awakeWithContext(context: AnyObject?) {
        super.awakeWithContext(context)
        glanceLable.setText("This is new Glance")
        glanceImage.setImage(UIImage(named: "[email protected]"))
        // Configure interface objects here.
    }

    override func willActivate() {
        // This method is called when watch view controller is about to be visible to user
        super.willActivate()
    }

    override func didDeactivate() {
        // This method is called when watch view controller is no longer visible
        super.didDeactivate()
    }

}

Can Anyone Help?

Upvotes: 0

Views: 382

Answers (1)

dan
dan

Reputation: 9825

If your image is in the WatchApp bundle then you want to use setImageNamed() so it loads the image on the watch instead of loading it on the phone and sending it over bluetooth. You also don't need to include the @2x or file extension, so it would just be:

glanceImage.setImageNamed("happy")

You should also be able to just set the image in the storyboard if it's always going to be the same.

Upvotes: 1

Related Questions