2 // FolioReaderChapterListCell.swift
5 // Created by Heberti Almeida on 07/05/15.
6 // Copyright (c) 2015 Folio Reader. All rights reserved.
11 class FolioReaderChapterListCell: UITableViewCell {
12 var indexLabel: UILabel?
14 override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
15 super.init(style: style, reuseIdentifier: reuseIdentifier)
17 self.indexLabel = UILabel()
20 func setup(withConfiguration readerConfig: FolioReaderConfig) {
22 self.indexLabel?.lineBreakMode = .byWordWrapping
23 self.indexLabel?.numberOfLines = 0
24 self.indexLabel?.translatesAutoresizingMaskIntoConstraints = false
25 self.indexLabel?.font = UIFont(name: "Avenir-Light", size: 17)
26 self.indexLabel?.textColor = readerConfig.menuTextColor
28 if let label = self.indexLabel {
29 self.contentView.addSubview(label)
31 // Configure cell contraints
32 var constraints = [NSLayoutConstraint]()
33 let views = ["label": label]
35 NSLayoutConstraint.constraints(withVisualFormat: "H:|-15-[label]-15-|", options: [], metrics: nil, views: views).forEach {
36 constraints.append($0 as NSLayoutConstraint)
39 NSLayoutConstraint.constraints(withVisualFormat: "V:|-16-[label]-16-|", options: [], metrics: nil, views: views).forEach {
40 constraints.append($0 as NSLayoutConstraint)
43 self.contentView.addConstraints(constraints)
47 required init?(coder aDecoder: NSCoder) {
48 fatalError("storyboards are incompatible with truth and beauty")
51 override func prepareForReuse() {
52 super.prepareForReuse()
54 // As the `setup` is called at each reuse, make sure the label is added only once to the view hierarchy.
55 self.indexLabel?.removeFromSuperview()