Jungsoo Nam
Jungsoo Nam

Reputation: 133

UITableViewCell text alignment center

 func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell: UITableViewCell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "ChatCell")

    // put the data
    cell.textLabel!.textColor = UIColor.redColor()
    cell.textLabel!.textAlignment = .Right
    cell.textLabel!.text = array[indexPath.row]

    return cell
}

I'm creating and using default UITableViewCell with textAlignment. Right, but it doesn't work.

By the way, Red color works well.

My environment is iOS9 with swift.

Thank you.

enter image description here

Upvotes: 1

Views: 1434

Answers (1)

Bhadresh Mulsaniya
Bhadresh Mulsaniya

Reputation: 2640

Try this

let cell:UITableViewCell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "ChatCell")

instead of

let cell: UITableViewCell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "ChatCell")

Upvotes: 3

Related Questions