2015-04-05 27 views
0

我試圖在一覽圖中顯示圖像。圖像格式爲.png,我已將其放入WatchKitApp軟件包中。Apple Watch:如何在圖像中顯示圖像

在一覽中,我在Glance中提供了默認組中的WKInterfaceImage。

下面是我的代碼來動態地找到它的圖像。

// 
// 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() 
    } 

} 

任何人都可以幫忙嗎?

+0

你有沒有想過這一個?我有同樣的問題。該圖像出現在Storyboard中,但不在實際的Watch上。 – bkwebhero 2015-09-29 14:09:04

回答

1

如果您的圖像位於WatchApp捆綁包中,則您希望使用setImageNamed(),以便將圖像加載到手錶上,而不是將其加載到手機上並通過藍牙發送。你也不需要包括@ 2倍或文件擴展名,所以這純粹是:

glanceImage.setImageNamed("happy") 

你也應該能夠只設置在圖像中的故事板,如果它總是將是相同的。

+0

沒有..它不工作....我已經試過.. – 2015-04-06 13:43:56

相關問題