如何遍历我的Swift视图中的所有UIButton? [英] How to loop through all UIButtons in my Swift view?
本文介绍了如何遍历我的Swift视图中的所有UIButton?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在Swift的视图中循环遍历所有 UIButtons
?我想将所有标题设置为,但我在Swift中的for循环发出错误。
How would I loop through all UIButtons
in my view in Swift? I would want to set all the titles to ""
, but my for-loop in Swift is giving an error.
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数组。
You need to iterate through the subViews array.
这篇关于如何遍历我的Swift视图中的所有UIButton?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文