Created
June 3, 2016 22:28
-
-
Save soffes/598c8033736564c0cbeceab6769588a1 to your computer and use it in GitHub Desktop.
Plain table view section header replacement
This file contains hidden or 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
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