forked from soffes/Static
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCustomTableViewCell.swift
41 lines (29 loc) · 1.25 KB
/
CustomTableViewCell.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import UIKit
import Static
final class CustomTableViewCell: UITableViewCell, CellType {
// MARK: - Properties
private lazy var centeredLabel: UILabel = {
let label = UILabel()
label.textAlignment = .Center
label.textColor = .whiteColor()
label.translatesAutoresizingMaskIntoConstraints = false
return label
}()
// MARK: - Initialization
override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
contentView.backgroundColor = .grayColor()
contentView.addSubview(centeredLabel)
let views = ["centeredLabel": centeredLabel]
var constraints: [NSLayoutConstraint] = NSLayoutConstraint.constraintsWithVisualFormat("|-[centeredLabel]-|", options: [], metrics: nil, views: views)
constraints += NSLayoutConstraint.constraintsWithVisualFormat("V:|-[centeredLabel]-|", options: [], metrics: nil, views: views)
NSLayoutConstraint.activateConstraints(constraints)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
// MARK: - CellType
func configure(row row: Row) {
centeredLabel.text = row.text
}
}