Watch OS 2设置图片的问题

6

我想在我的WKInterfaceController中添加一张图片,但是...

Xcode告诉我:

在手表上找不到名为"circle44"的图片

@IBOutlet var cirlceImage: WKInterfaceImage!
override func awakeWithContext(context: AnyObject?) {
    super.awakeWithContext(context)

    cirlceImage.setImageNamed("circle44")
}
2个回答

7

好的,我找到了结果,图片必须在你的WatchKt应用程序中而不是在扩展程序中。另外,随着应用瘦身技术的增加,手表不再搜索1x图像,因为它们都应该是2x的。正如你看到的那样!

import WatchKit
import Foundation


class InterfaceController: WKInterfaceController {


    @IBOutlet var cirlceImage: WKInterfaceImage!

    override func awakeWithContext(context: AnyObject?) {
        super.awakeWithContext(context)
        cirlceImage.setImageNamed("circle94")


    }

    override func willActivate() {
        super.willActivate()

    }

    override func didDeactivate() {
        super.didDeactivate()

    }
}

奇怪的是,使用setImageNamed("image_name")可以工作,但是setImage(UIImage(named:"image_name"))却不行。 - eagerMoose

0

将图片添加到imagees.xcassets中,选择Apple Watch,然后将2x添加到其中

enter image description here


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接