Created
August 23, 2020 04:19
-
-
Save rahulsingh1101/0a231551c742ed510ec5ed0dbbdefe20 to your computer and use it in GitHub Desktop.
Useful Extensions
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 addAutolayoutSubview(_ view: UIView){ | |
view.translatesAutoresizingMaskIntoConstraints = false | |
addSubview(view) | |
} | |
func apply<T:UIView>(_ view: T, completion:((T))->Void){ | |
completion(view) | |
} | |
} | |
extension UIStackView { | |
func addArrangedAutolayoutSubview(_ view: UIView){ | |
view.translatesAutoresizingMaskIntoConstraints = false | |
addArrangedSubview(view) | |
} | |
func addArrangedAutolayoutSubviews(_ view: [UIView]){ | |
view.forEach { | |
$0.translatesAutoresizingMaskIntoConstraints = false | |
addArrangedSubview($0) | |
} | |
} | |
} | |
extension UIStackView { | |
convenience init(alignment: UIStackView.Alignment, distribution: UIStackView.Distribution, axis: NSLayoutConstraint.Axis, spacing: CGFloat) { | |
self.init() | |
self.axis = axis | |
self.alignment = alignment | |
self.distribution = distribution | |
self.spacing = spacing | |
} | |
} | |
extension UIViewController { | |
func alert(title: String,message: String,actionTitles: [String],actionStyle: [UIAlertAction.Style],action: [((UIAlertAction) -> Void)]) { | |
let alert = UIAlertController(title: title, message: message, | |
preferredStyle: .alert) | |
for (index, title) in actionTitles.enumerated() { | |
let action = UIAlertAction(title: title, style: actionStyle[index], handler: action[index]) | |
alert.addAction(action) } | |
self.present(alert, animated: true, completion: nil) | |
} | |
func alert(title: String,message: String) { | |
let alert = UIAlertController(title: title, message: message, | |
preferredStyle: .alert) | |
let action = UIAlertAction(title: "OK", style: .default, handler: { (action) in | |
}) | |
alert.addAction(action) | |
self.present(alert, animated: true, completion: nil) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment