我正在尝试格式化 UIViewController 的 detailTextLabel 属性中的数字位置。UIViewTable 的 detailTextLabel 部分中的数字太靠右了(如图所示)。
我试过了:
cell.detailTextLabel?.textAlignment = .center
但它不起作用。我在界面生成器中尝试了.left
、.right
和各种设置。.justified
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "PracticeWord", for: indexPath)
let sortedPracticeWord = sortedPracticeWords[indexPath.row]
print("practiceWord is: \(sortedPracticeWord)")
let split = sortedPracticeWord.components(separatedBy: "::")
cell.textLabel?.text = split[0]
cell.textLabel?.textColor = UIColor.white
cell.selectedBackgroundView = UIView()
cell.selectedBackgroundView!.backgroundColor = UIColor(white: 1, alpha: 0.20)
cell.textLabel?.text = split[1]
cell.detailTextLabel?.text = split[2]
cell.detailTextLabel?.textAlignment = .center
print("cell is: \(cell)")
return cell
}
我希望每个数字都在“错误”一词的“g”下结束。