mirror of
https://github.com/whoeevee/EeveeSpotifyReborn.git
synced 2026-01-09 00:23:20 +01:00
35 lines
906 B
Swift
35 lines
906 B
Swift
import UIKit
|
|
|
|
extension UIView {
|
|
func hasParent(matching regex: String) -> Bool {
|
|
guard let parent = self.superview else {
|
|
return false
|
|
}
|
|
|
|
let parentClassName = NSStringFromClass(type(of: parent))
|
|
if parentClassName ~= regex {
|
|
return true
|
|
} else {
|
|
return parent.hasParent(matching: regex)
|
|
}
|
|
}
|
|
|
|
func subviews(matching regex: String) -> [UIView] {
|
|
var matchingSubviews = [UIView]()
|
|
var stack = [self]
|
|
|
|
while !stack.isEmpty {
|
|
let currentView = stack.removeLast()
|
|
|
|
for subview in currentView.subviews {
|
|
if NSStringFromClass(type(of: subview)) ~= regex {
|
|
matchingSubviews.append(subview)
|
|
}
|
|
stack.append(subview)
|
|
}
|
|
}
|
|
|
|
return matchingSubviews
|
|
}
|
|
}
|