Skip to content

Instantly share code, notes, and snippets.

@gordinmitya
Created October 17, 2018 11:11
Show Gist options
  • Save gordinmitya/89ab581613e65df8521b4445ab68f897 to your computer and use it in GitHub Desktop.
Save gordinmitya/89ab581613e65df8521b4445ab68f897 to your computer and use it in GitHub Desktop.
class CityCell: BaseCell {
override class var id: String {return "CityCell"}
var checkedImage: UIImageView = {
let iv = UIImageView()
iv.contentMode = .scaleAspectFill
iv.clipsToBounds = true
iv.translatesAutoresizingMaskIntoConstraints = false
iv.heightAnchor.constraint(equalToConstant: 20).isActive = true
iv.widthAnchor.constraint(equalToConstant: 20).isActive = true
iv.isHidden = true
return iv
}()
var nameLabel: UILabel = {
let l = UILabel()
l.translatesAutoresizingMaskIntoConstraints = false
return l
}()
override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
backgroundColor = .mainGray
contentView.backgroundColor = .mainGray
addSubview(nameLabel)
addSubview(checkedImage)
nameLabel.rightAnchor.constraint(equalTo: rightAnchor, constant: -16).isActive = true
nameLabel.centerYAnchor.constraint(equalTo: centerYAnchor).isActive = true
nameLabel.leftAnchor.constraint(equalTo: checkedImage.rightAnchor, constant: 8).isActive = true
checkedImage.leftAnchor.constraint(equalTo: leftAnchor, constant: 8).isActive = true
checkedImage.centerYAnchor.constraint(equalTo: centerYAnchor).isActive = true
checkedImage.image = UIImage(named: "checked")
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func create(_ city: City) -> CityCell {
nameLabel.text = city.name
onSelect = {PreferenceManager.set(PreferenceManager.PreferenceKeys.city, city.alias!)}
layoutIfNeeded()
return self
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment