Skip to content

Instantly share code, notes, and snippets.

@mikehouse
Created August 21, 2019 17:17
Show Gist options
  • Save mikehouse/c46ef2e14589e923698b54b586847736 to your computer and use it in GitHub Desktop.
Save mikehouse/c46ef2e14589e923698b54b586847736 to your computer and use it in GitHub Desktop.
UIView Utilities
import UIKit
extension UIView {
func findFirstSubview(with className: String) -> UIView? {
if String(describing: type(of: self)) == className {
return self
}
for subview in subviews {
if String(describing: type(of: self)) == className {
return subview
} else {
if let view = subview.findFirstSubview(with: className) {
return view
}
}
}
return nil
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment