Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Heilum/cf43a5675ee0dba53d7b259fbd02274c to your computer and use it in GitHub Desktop.
Save Heilum/cf43a5675ee0dba53d7b259fbd02274c to your computer and use it in GitHub Desktop.
extension UIView {
func findDescendantViewsOfType<T: Any>(_ subViewType:T.Type) -> [T]{
var rs = [T]()
if self is T {
rs.append(self as! T)
}
for view in self.subviews {
rs.append(contentsOf: view.findDescendantViewsOfType(T.self))
}
return rs
}
}
class SSAlertController: UIAlertController {
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews();
//adjust alert-action's font
let stackViews = self.view.findDescendantViewsOfType(UIStackView.self);
if let firstStackView = stackViews.first{
let labels = firstStackView.findDescendantViewsOfType(UILabel.self)
for l in labels{
l.font = SSCommonVC.getFont(size: 16)!
}
}
// adjust title's font
if let title = self.title{
self.setValue(NSAttributedString(string: title, attributes: [NSAttributedString.Key.foregroundColor : SSCommonVC.app_deep_blue_bg,NSAttributedString.Key.font : SSCommonVC.getFont(size: 24)!]), forKey: "attributedTitle")
}
// adjust message's font
if let msg = self.message{
self.setValue(NSAttributedString(string: msg, attributes: [NSAttributedString.Key.foregroundColor : SSCommonVC.app_deep_blue_bg,NSAttributedString.Key.font : SSCommonVC.getFont(size: 18)!]), forKey: "attributedMessage")
}
//adjust alert-action's color
self.view.tintColor = SSCommonVC.app_deep_blue_bg;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment