Skip to content

Instantly share code, notes, and snippets.

@alemar11
Forked from isoiphone/!UIView+ForEach.swift
Created April 25, 2016 15:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alemar11/991a26cdd82b41428f835408e326fffe to your computer and use it in GitHub Desktop.
Save alemar11/991a26cdd82b41428f835408e326fffe to your computer and use it in GitHub Desktop.
extension UIView {
func forEachSubviewOfType<V: UIView>(type: V.Type, @noescape apply block: V -> Void) {
for view in subviews {
if let view = view as? V {
block(view)
} else {
view.forEachSubviewOfType(V.self, apply: block)
}
}
}
}
searchController.searchBar.forEachSubviewOfType(UITextField.self) { textField in
textField.textColor = .whiteColor()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment