我正试图在我的UIViewControllers的超级视图中找到我的UILabels.这是我的代码:
func watch(startTime:String, endTime:String) {
if superview == nil {println("NightWatcher: No viewcontroller specified");return}
listSubviewsOfView(self.superview!)
}
func listSubviewsOfView(view: UIView) {
var subviews = view.subviews
if (subviews.count == 0) { return }
view.backgroundColor = UIColor.blackColor()
for subview in subviews {
if subview.isKindOfClass(UILabel) {
// do something with label..
}
self.listSubviewsOfView(subview as UIView)
}
}
Run Code Online (Sandbox Code Playgroud)
这是在Objective-C中推荐的方式,但在Swift中我除了UIViews和CALayer之外什么也得不到.我肯定在提供给这个方法的视图中有UILabel.我错过了什么?
我的UIViewController中的调用:
NightWatcher(view: self.view).watch("21:00", endTime: "08:30") // still working on
Run Code Online (Sandbox Code Playgroud)