我必须以编程方式添加按钮列表
I have to add a list of button programmatically
如何使用 WatchKit 在 swift 2 中以编程方式添加一些按钮?
You can't dynamically create views in WatchKit. You need to create
your entire interface in a storyboard. You can have elements of your
storyboard hidden and then programmatically unhide them.
参考:Create imageView programmatically in Watch Kit
您可以创建 table 而不是按钮。因此,您可以获得多个可点击的链接。
这是@natashatherobot 的教程http://natashatherobot.com/watchkit-create-table/
教程片段:
private func loadTableData() {
minionTable.setNumberOfRows(minions.count, withRowType: "MinionTableRowController")
for (index, minionName) in enumerate(minions) {
let row = minionTable.rowControllerAtIndex(index) as! MinionTableRowController
row.interfaceLabel.setText(minionName)
row.interfaceImage.setImage(UIImage(named: minionName))
}
}
如何使用 WatchKit 在 swift 2 中以编程方式添加一些按钮?
You can't dynamically create views in WatchKit. You need to create your entire interface in a storyboard. You can have elements of your storyboard hidden and then programmatically unhide them.
参考:Create imageView programmatically in Watch Kit
您可以创建 table 而不是按钮。因此,您可以获得多个可点击的链接。
这是@natashatherobot 的教程http://natashatherobot.com/watchkit-create-table/
教程片段:
private func loadTableData() {
minionTable.setNumberOfRows(minions.count, withRowType: "MinionTableRowController")
for (index, minionName) in enumerate(minions) {
let row = minionTable.rowControllerAtIndex(index) as! MinionTableRowController
row.interfaceLabel.setText(minionName)
row.interfaceImage.setImage(UIImage(named: minionName))
}
}