Created
October 17, 2018 11:11
-
-
Save gordinmitya/89ab581613e65df8521b4445ab68f897 to your computer and use it in GitHub Desktop.
This file contains 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
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