Skip to content

Instantly share code, notes, and snippets.

View GenoZhou's full-sized avatar

Geno GenoZhou

View GitHub Profile
@GenoZhou
GenoZhou / UITableView.swift
Created November 5, 2017 15:34
Swift 4 UITableView extensions.
public protocol ReusableView: class { }
extension ReusableView where Self: UIView {
public static var reuseIdentifier: String {
return String(describing: self)
}
}
extension UITableViewCell: ReusableView { }
extension UITableViewHeaderFooterView: ReusableView { }
@GenoZhou
GenoZhou / UIView.swift
Last active November 5, 2017 15:34
Swift 4 UIView extensions.
extension UIView {
public func addSubviews(_ subviews: [UIView], tAMIC: Bool = false) {
for subview in subviews {
addSubview(subview)
subview.translatesAutoresizingMaskIntoConstraints = false
}
}
}
@GenoZhou
GenoZhou / UIView+AutoLayout.swift
Last active November 24, 2017 10:41
Swift 4 UIView Autolayout extensions.
extension UIView {
@discardableResult
public func constrainEdges(to view: UIView) -> [NSLayoutConstraint] {
let constraints = [
leadingAnchor.constraint(equalTo: view.leadingAnchor),
topAnchor.constraint(equalTo: view.topAnchor),
trailingAnchor.constraint(equalTo: view.trailingAnchor),
bottomAnchor.constraint(equalTo: view.bottomAnchor)
]
NSLayoutConstraint.activate(constraints)