Skip to content

Instantly share code, notes, and snippets.

@soffes
Created June 3, 2016 22:28
Show Gist options
  • Save soffes/598c8033736564c0cbeceab6769588a1 to your computer and use it in GitHub Desktop.
Save soffes/598c8033736564c0cbeceab6769588a1 to your computer and use it in GitHub Desktop.
Plain table view section header replacement
import UIKit
class SectionHeaderView: UIView {
// MARK: - Properties
let textLabel: UILabel = {
let label = UILabel()
label.translatesAutoresizingMaskIntoConstraints = false
label.font = .boldSystemFontOfSize(17)
return label
}()
// MARK: - Initializers
convenience init() {
self.init(frame: CGRect(x: 0, y: 0, width: 320, height: 28))
}
override init(frame: CGRect) {
super.init(frame: frame)
autoresizingMask = [.FlexibleWidth]
addSubview(textLabel)
NSLayoutConstraint.activateConstraints([
textLabel.leadingAnchor.constraintEqualToAnchor(leadingAnchor, constant: 16),
textLabel.trailingAnchor.constraintLessThanOrEqualToAnchor(trailingAnchor, constant: -16),
textLabel.topAnchor.constraintEqualToAnchor(topAnchor, constant: 4),
textLabel.bottomAnchor.constraintEqualToAnchor(bottomAnchor, constant: -4)
])
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment