簡體   English   中英

Apple Watch:如何在Glance中顯示圖像

[英]Apple Watch: how to show image in Glance

我正在嘗試在Glance View中顯示圖像。 圖像格式為.png,我將其放置在WatchKitApp捆綁包中。

在Glance中,我在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: "happy@2x.png"))
        // 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()
    }

}

有人可以幫忙嗎?

如果您的圖像在WatchApp捆綁包中,則您要使用setImageNamed()以便將其加載到手表上,而不是將其加載到手機上並通過藍牙發送。 您也不需要包含@ 2x或文件擴展名,因此只需:

glanceImage.setImageNamed("happy")

如果始終保持相同,您還應該能夠在情節提要中設置圖像。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM