Created
August 21, 2019 17:17
-
-
Save mikehouse/c46ef2e14589e923698b54b586847736 to your computer and use it in GitHub Desktop.
UIView Utilities
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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