WKInterfacePicker标题

时间:2016-07-18 16:43:47

标签: swift apple-watch watch-os-2

您知道如何为watchOS选择器添加静态标题吗?标题看起来像这样,它表示第1项。

Black square with Apple Watch picker deploying colours: Red, Green, highlighted in green with bright green caption on top which says item 1

我已在Interface Builder中选择了合适的样式:

Displays macOS drop down menu with 3 options. Outline with caption is selected.

我的代码:

override func awakeWithContext(context: AnyObject?) {
    super.awakeWithContext(context)

    let item1 = WKPickerItem()
    item1.title = "10"
    let item2 = WKPickerItem()
    item2.title = "20"
    let item3 = WKPickerItem()
    item3.title = "30"
    picker.setItems([item1, item2, item3])

    picker.focus()
}

我进入模拟器的结果:

Apple Watch screenshot with the picker and 2 buttons. Picker also outlined in green but doesn't have any caption on top.

如何在选择器顶部添加缺少的标题?

1 个答案:

答案 0 :(得分:3)

您应该为每个WKPickerItem提供标题:

let item1 = WKPickerItem()
item1.title = "10"
item1.caption = "CAPTION!"