如何更改标签“取消"?来自 Apple Watch 中的 modal segue [英] How can I change the label "Cancel" from modal segue in Apple Watch

查看:17
本文介绍了如何更改标签“取消"?来自 Apple Watch 中的 modal segue的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我打开模态视图时,如何更改出现在左上角的取消"标签......我希望它是一个带有图像的按钮.

How to change the label appearing at the top left corner that says "Cancel" when I open a modal view... I would like it to be a button with an image.

推荐答案

标签 Cancel 是模态呈现的 WKInterfaceController 的默认标题",它出现在 Apple Watch 状态栏上.

The label Cancel is the default 'title' of a modally presented WKInterfaceController, which appears on the Apple Watch status bar.

>

用图片替换标题

无法隐藏状态栏,也无法在状态栏中显示图像,既不能作为此链接的一部分,也不能替换此链接.

It is not possible to hide the status bar, nor is it possible to display an image in the status bar, neither as part of this link nor to replace this link.

然而,您可以将标题设置为新的字符串值.例如,您可能希望将 Cancel 替换为 Close.有四种方法可以设置此标题,如下所述.确保您阅读底部的注意,因为在大多数情况下可能只有选项 1 是可以接受的.

You can however set the title to a new string value. For instance, you might well want to replace Cancel with Close. There are four ways that you can set this title, which are outlined below. Ensure you read the Note at the bottom as likely only Option 1 will be acceptable in most circumstances.

  1. 您可以在 Interface Builder 中设置模态呈现的 WKInterfaceController 的标题.只需在属性检查器中设置 Title 属性.当然,每个 WKInterfaceController 只能以这种方式设置一个静态标题,当然,尽管可以使用上述任何机制在运行时动态更改它.

  1. You can set the title of the modally presented WKInterfaceController in Interface Builder. Simply set the Title attribute in the Attributes Inspector. Only a single static title can be set this way for each WKInterfaceController, of course, although it can be changed dynamically at runtime using any of the mechanisms outlined above.

您可以在 init 方法中为模态呈现的 WKInterfaceController 设置标题:

You can set the title in the init method for the modally presented WKInterfaceController:

override init () {
    super.init ()        
    self.setTitle("Close")
}

  • 可以直接在模态呈现的WKInterfaceController的awakeWithContext方法中设置标题:

  • You can set the title directly in the awakeWithContext method of the modally presented WKInterfaceController:

    override func awakeWithContext(context: AnyObject?) {
        super.awakeWithContext(context)
        self.setTitle("Close")
    }
    

  • 您可以使用上下文变量将标题传递给模态呈现的 WKInterfaceController.在界面生成器中,在控制器的属性检查器中设置 identifier 以进行模态呈现.(在这个例子中,它被设置为modalController".)然后你通过传递所需的标题作为上下文来呈现控制器:

  • You can pass the title to the modally presented WKInterfaceController using the context variable. In interface builder, set the identifier in the Attributes Inspector of the controller to be presented modally. (In this example, it was set to "modalController".) You then present the controller by passing the desired title as the Context:

    self.presentControllerWithName("modalController", context: "Close")
    

    然后,在模态呈现的控制器中:

    Then, in the modally presented controller:

    override func awakeWithContext(context: AnyObject?) {
        super.awakeWithContext(context)                
        self.setTitle(context as? String)
    }
    

  • 注意:

    WatchKit 当前的预期行为"几乎可以肯定意味着在大多数用例中只有第一个选项被视为可以接受.这是因为目前,对于其他三个选项,您最初会在视图加载时看到默认标题,然后将替换为您使用 setTitle 设置的文本.awakeWithContext 在视图加载后按设计运行,但即使在 init 中使用 setTitle 也无法避免默认标题的初始显示.

    Note:

    The current 'intended behaviour' of WatchKit almost certainly means that only the first option will be seen as acceptable in most use cases. This is because currently, for the other three options you will initially see the default title for the view as it loads, which will then be replaced with the text you set using setTitle. awakeWithContext runs by design after the view has loaded, but even using setTitle in init does not avoid the initial display of the default title.

    上面列出的第一个选项将 Cancel 替换为视图的新默认标题.如果您将界面构建器中的自定义标题与下面的选项 2-4 中的任何一个结合起来,您会看到完全相同的症状(初始标题然后被您的 setTitle 替换),只是具有不同的初始标题.

    The first option outlined above replaces Cancel with a new default title for the view. If you combine a custom Title in Interface builder with any of Options 2-4 below, you see exactly the same symptom (initial title then being replaced with your setTitle), just with a different initial title.

    这篇关于如何更改标签“取消"?来自 Apple Watch 中的 modal segue的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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