【问题标题】:I have to add a list of button programmatically我必须以编程方式添加按钮列表
【发布时间】:2015-07-29 10:43:54
【问题描述】:

如何使用 WatchKit 在 swift 2 中以编程方式添加一些按钮?

【问题讨论】:

    标签: swift button watchkit


    【解决方案1】:

    您不能在 WatchKit 中动态创建视图。你需要创建 故事板中的整个界面。你可以有你的元素 故事板隐藏,然后以编程方式取消隐藏。

    参考:Create imageView programmatically in Watch Kit

    您可以创建表格而不是按钮。因此,您可以获得多个可点击的链接。

    这是@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))
        }
    }
    

    【讨论】:

    • 谢谢!我正在尝试使用表格,但我没有找到好的例子。你有吗?
    • @LucaMarconato 查看教程的更新链接
    • @LucaMarconato 欢迎随时欢迎。 :)
    猜你喜欢
    • 2012-06-20
    • 1970-01-01
    • 2020-09-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多