Created
May 15, 2020 03:31
-
-
Save Heilum/cf43a5675ee0dba53d7b259fbd02274c to your computer and use it in GitHub Desktop.
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
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