ios - 如何循环遍历我的 Swift View 中的所有 UIButton?

标签 ios xcode swift

我如何在 Swift 的 View 中循环遍历所有 UIButtons?我想将所有标题设置为 "",但我在 Swift 中的 for 循环出错。

for btns in self.view as [UIButton] {
  // set the title to ""
}

最佳答案

这段代码应该可以工作:

for view in self.view.subviews as [UIView] {
    if let btn = view as? UIButton {
        btn.setTitleForAllStates("")
    }
}

您需要遍历 subViews 数组。

关于ios - 如何循环遍历我的 Swift View 中的所有 UIButton?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25715022/

相关文章:

ios - touchesbegan 用于关闭 ScrollView 下的键盘 TextView 不起作用

ios - Swift 表格 View 单元格选择更改复选框图像

ios - 使用 Apple 的 PDFKit 框架更改 PDF 中的文本

objective-c - 隐藏 JSQMessageViewController 气泡中的链接

ios - 通过对象委托(delegate)强制 'pass-by-value'

ios - 如何获得像 “mm:ss”格式的歌曲的实际持续时间?

swift - 如何使用 NSArray 绑定(bind)在两个 NSTableView 中显示两个 1 米相关的 CoreData 实体

iphone - 更新到 Xcode 4.6 后出现超过 1000 个编译器错误

iphone - 由于内存压力而终止的应用程序

swift - array.last 和一般嵌套数组复制/访问突变混淆