swift - WKInterfacePicker 标题

标签 swift apple-watch watchos-2

您知道如何向 watchOS 选择器添加静态字幕吗?标题看起来像这样,上面写着Item 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.

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

最佳答案

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

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

关于swift - WKInterfacePicker 标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38442008/

相关文章:

swift - CGImage 到 MPSTexture 或 MPSImage

ios - Swift:协议(protocol)扩展中的静态属性可以被覆盖,但为什么呢?

swift - Swift 中的 SpriteKit 颜色填充动画

watchkit - HKWorkoutSession 没有将应用程序放在 Apple Watch 前面

ios - 如何避免在 SpriteKit 中传递 currentTime ?

ios - 在 SJSegmentedViewController 中处理 ViewController 之间的数据

ios - WatchKit - 如何在首次启动时获取数据?

ios - 在 iOS 和 WatchKit 中使用 Cocoa Touch Framework

ios - 与 WatchKit 应用程序的行为不一致 - Swift

ios - WatchSimulator 3.1 SDK不支持x86_64体系结构?