func applyStyle<T : UIView>(block:((T)->Void)) {
if type(of: self) == T.self {
block(self as! T)
return
}
if type(of: self) == UIStackView.self {
for subview in self.subviews {
subview.applyStyle(block: block)
}
return
}
if type(of: self) == UIView.self {
for subview in self.subviews {
subview.applyStyle(block: block)
}
return
}
if type(of: self) == UIScrollView.self {
for subview in self.subviews {
subview.applyStyle(block: block)
}
return
}
}
调用
self.scrollView.applyStyle { (textField:QMUITextField) in
textField.textInsets = UIEdgeInsets.zero
}
self.scrollView.applyStyle { (label:UILabel) in
label.textColor = .white
}