Last active
March 27, 2018 07:08
-
-
Save fmessina/f0535c94608bf84d4aff6602f2c77478 to your computer and use it in GitHub Desktop.
Add a custom label on the right on UITableViewCell
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
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { | |
let cellIdentifier = "CellIdentifier" | |
let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier) ?? UITableViewCell(style: .value1, reuseIdentifier: cellIdentifier) | |
let label = UILabel() | |
label.textAlignment = .right | |
label.backgroundColor = UIColor.clear | |
label.textColor = UIColor.gray | |
label.translatesAutoresizingMaskIntoConstraints = false | |
cell.detailTextLabel?.text = "TEST" | |
cell.addSubview(label) | |
label.trailingAnchor.constraint(equalTo: cell.trailingAnchor, constant: -30.0).isActive = true | |
label.centerYAnchor.constraint(equalTo: cell.centerYAnchor, constant: 0).isActive = true | |
cell.textLabel?.text = "indexPath.row \(indexPath.row)" | |
return cell | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment