【发布时间】:2017-07-31 07:59:12
【问题描述】:
我正在使用 SearchTextField 窗格来显示预测文本。
https://github.com/apasccon/SearchTextField
以下代码使用显示列表构建表格。
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
var cell = tableView.dequeueReusableCell(withIdentifier: SearchTextField.cellIdentifier)
if cell == nil {
cell = UITableViewCell(style: .subtitle, reuseIdentifier: SearchTextField.cellIdentifier)
}
//cell!.backgroundColor = UIColor.clear
cell!.backgroundColor = UIColor.red
cell!.layoutMargins = UIEdgeInsets.zero
cell!.preservesSuperviewLayoutMargins = false
cell!.textLabel?.font = theme.font
cell!.detailTextLabel?.font = UIFont(name: theme.font.fontName, size: theme.font.pointSize * fontConversionRate)
cell!.textLabel?.textColor = theme.fontColor
cell!.detailTextLabel?.textColor = theme.fontColor
cell!.textLabel?.text = filteredResults[(indexPath as NSIndexPath).row].title
cell!.detailTextLabel?.text = filteredResults[(indexPath as NSIndexPath).row].subtitle
cell!.textLabel?.attributedText = filteredResults[(indexPath as NSIndexPath).row].attributedTitle
cell!.detailTextLabel?.attributedText = filteredResults[(indexPath as NSIndexPath).row].attributedSubtitle
cell!.imageView?.image = filteredResults[(indexPath as NSIndexPath).row].image
cell!.selectionStyle = .none
cell!.detailTextLabel?.textAlignment = .right
cell!.textLabel?.textAlignment = .right
return cell!
}
生成一个匹配标题列表作为标签,如图所示
所以我的问题是如何让我的标签从右到左显示数据?
感谢您提供的任何帮助
【问题讨论】:
-
你想让它对齐吗?
-
是的。这正是我想要实现的目标
-
(style: .subtitle不支持正确的文本对齐,如果您需要使用自定义标签,请将您的样式更改为(style: .Default) -
能否请您解释一下如何更改样式以及在哪里更改?