本文介绍了如何更改标签“取消”?来自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.

推荐答案

标签取消是模态呈现的WKInterfaceController的默认标题,它出现在Apple Watch状态bar。

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.

但是,您可以将标题设置为新的字符串值。例如,您可能希望将取消替换为关闭。您可以通过以下四种方式设置此标题。请确保您阅读底部的注意,因为在大多数情况下,只有选项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的标题。只需在Attributes Inspector中设置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.

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

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。在界面构建器中,在要以模态方式呈现的控制器的属性检查器中设置标识符。 (在此示例中,它被设置为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.

    上面列出的第一个选项取代了取消,并为视图添加新的默认标题。如果将界面构建器中的自定义标题与下面的选项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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

    10-27 07:40