4

I am trying to display a page like the following

page title (left align)

region name(center align)

people in the region(subtitle with email in the detail label)

But if I choose subtitle as cell style, everything will be left aligned and I cannot change them in the code. Then If I choose custom as style the detailtextlabel will not show.

if(poDetailList.LastName == "POName"){
        cell.backgroundColor = SharedClass().coopGroupHeaderColor
        let selectedColor = UIView()
        selectedColor.backgroundColor = SharedClass().coopGroupHeaderColor
        cell.selectedBackgroundView = selectedColor
        cell.textLabel?.textColor = UIColor.blackColor()
        cell.textLabel?.font = UIFont.boldSystemFontOfSize(15.0)
        cell.textLabel?.textAlignment = .Center
        cell.accessoryType = .None
        var t_header = ""
        if(POShort != "OTHER" && POShort != "all" && POShort != "invalid"){
            t_header = POName
        }
        else{
            t_header = POName
        }
        cell.textLabel?.text = t_header
        cell.detailTextLabel?.text = ""
        cell.userInteractionEnabled = false;
    } else{
        cell.backgroundColor = indexPath.row % 2 == 0 ? UIColor.clearColor() : SharedClass().cellBackGroundColor
        let selectedColor = UIView()
        selectedColor.backgroundColor = SharedClass().selectedCellColor
        cell.selectedBackgroundView = selectedColor
        cell.textLabel?.font = UIFont.boldSystemFontOfSize(15.0)
        cell.textLabel?.textAlignment = .Left
        cell.accessoryType = UITableViewCellAccessoryType.DisclosureIndicator
        var t_header = poDetailList.FirstName
        cell.textLabel?.text = "Name:" + poDetailList.FirstName + " " + poDetailList.LastName
        cell.detailTextLabel?.text = "Not Responded In Days:" + poDetailList.DaysNotResponded
        cell.userInteractionEnabled = true;
    }

Can anyone help me with this?

Thank you very much

Jun Luo
  • 139
  • 1
  • 13

1 Answers1

6

Set Alignment for both label

cell.textLabel?.textAlignment = .Left
cell.detailTextLabel?.textAlignment = .Right

i hope it work!!!

Memon Irshad
  • 972
  • 1
  • 8
  • 17
  • Thank you for your advice and sorry that I might not be clear. My problem is I set the cell style to subtitle in storyboard and as a result, every cell is left aligned even if i set cell.textLabel?.textAlignment = .Left – Jun Luo Jun 02 '15 at 13:45
  • Sorry, even if I set cell.textLabel?textAlignment=.Center – Jun Luo Jun 02 '15 at 14:05
  • If you create own label and set as per choice without using textLabel or DetailLabel – Memon Irshad Jun 03 '15 at 05:44
  • Thank you for your suggestion. I will try that. If it works i will mark it as the correct answer – Jun Luo Jun 03 '15 at 16:08