Apple Watch 设置背景图片 [英] Apple Watch set background image

查看:52
本文介绍了Apple Watch 设置背景图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何以编程方式设置我的 WatchKit 应用背景图片?我需要在代码中设置它,因为它会根据可变大小而变化,我们需要在图像上放置一个标签.

How can I programmatically set my WatchKit App background image? I need to set this in code as it changes depending on variable size and we need to place a label over the image.

推荐答案

无法在 WatchKit 中以编程方式设置整个 Watch App 页面上的背景图像... 整个页面的背景图片目前只能在它出现的Interface Builder中设置.

It is not possible to programatically set the background image on an entire Watch App page in WatchKit... a background image for the whole page can at the current time only be set in Interface Builder it appears.

但是,您可以将图片设置为标签后面的背景,并使该图片充满屏幕:

However, you can set a picture as a background behind a label, and make that image fill the screen:

  1. 在您的 WatchKit 场景中创建一个组.您可能希望为视图设置自定义大小属性(例如,在大小设置下,宽度和高度为相对于容器",值为1"以填充场景.
  2. 将所需的背景图片设置为组的背景属性.
  3. 将您的标签放入组内,并根据需要设置格式.

此组图片也可以通过编程方式设置:

This group image can also be set programmatically:

  1. 以通常的方式将组的 IBOutlet 设置为您的 WatchKit 扩展,方法是按住 Ctrl 键从组中拖动到扩展中的接口控制器类.
  2. 确保您的图片作为Copy Bundle Resource"包含在 WatchKit 应用(而不是扩展程序)中.
  3. 在扩展的 awakeWithContext 方法中设置背景图片(假设你调用了你的 IBOutlet 'group'):

  1. Set an IBOutlet for the group to your WatchKit Extension in the usual fashion, by Ctrl-dragging from the group to your Interface Controller class in the Extension.
  2. Ensure your image is included as a 'Copy Bundle Resource' in your WatchKit App (not the Extension).
  3. Set the background image in the awakeWithContext method of the Extension (assuming you called your IBOutlet 'group'):

[self.group setBackgroundImage:[UIImage imageNamed:@"myImageName.png"]];

这两种技术当然不是相互独立的.您可以在 Interface Builder 中设置初始图像,然后在需要时以编程方式替换它.

The two techniques are of course not mutually independent. You can set an initial image in Interface Builder, and then replace it programatically later if that is called for.

这篇关于Apple Watch 设置背景图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆