Skip to content

Instantly share code, notes, and snippets.

@fmessina
Last active March 27, 2018 07:08
Show Gist options
  • Save fmessina/f0535c94608bf84d4aff6602f2c77478 to your computer and use it in GitHub Desktop.
Save fmessina/f0535c94608bf84d4aff6602f2c77478 to your computer and use it in GitHub Desktop.
Add a custom label on the right on UITableViewCell
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