【问题标题】:Swift UITableViewCell AlignmentSwift UITableViewCell 对齐
【发布时间】:2015-08-16 07:06:42
【问题描述】:

我正在尝试显示如下页面

页面标题(左对齐)

区域名称(居中对齐)

该地区的人(详细标签中带有电子邮件的副标题)

但如果我选择字幕作为单元格样式,所有内容都将左对齐,我无法在代码中更改它们。那么如果我选择自定义作为样式,detailtextlabel 将不会显示。

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;
    }

谁能帮我解决这个问题?

非常感谢

【问题讨论】:

  • 只能设置文本标签对齐,不能设置detailtextlabel对齐

标签: uitableview swift alignment custom-controls subtitle


【解决方案1】:

为两个标签设置对齐方式

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

希望能成功!!!

【讨论】:

  • 感谢您的建议,很抱歉我可能不清楚。我的问题是我在情节提要中将单元格样式设置为副标题,因此,即使我设置了 cell.textLabel?.textAlignment = .Left,每个单元格都左对齐
  • 对不起,即使我设置了 cell.textLabel?textAlignment=.Center
  • 如果您创建自己的标签并根据选择设置而不使用 textLabel 或 DetailLabel
  • 感谢您的建议。我会试试的。如果有效,我会将其标记为正确答案
猜你喜欢
  • 2012-06-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-07-16
  • 2011-09-16
  • 2023-03-29
相关资源
最近更新 更多