繁体   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