【问题标题】:How to align on the right only a part of the string of the UItablecell如何仅在右侧对齐 UItablecell 的字符串的一部分
【发布时间】:2020-04-19 03:52:38
【问题描述】:

在表格视图单元格中显示时,是否可以仅将字符串的一部分右对齐?

这是我的示例代码:

var arrayAnimals:Array<String> = ["Dogs \(self.arrayData[1])g","Cats  \(self.arrayData[2])g","Rabbits \(self.arrayData[3])g","Crocodiles \(self.arrayData[4])g"]

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let  cell = tableView.dequeueReusableCell(withIdentifier: "MyCell", for: indexPath)

    cell.textLabel!.text = arrayAnimals[indexPath.row]

    return cell
}

在这种情况下,是否可以在每个单元格中将动物的名称左对齐并右对齐其匹配数据?

提前谢谢你!

【问题讨论】:

标签: arrays swift uitableview


【解决方案1】:

这个问题最简单的解决方案是使用 value1 的单元格类型(而不是默认值),这将在 textLabel 的右侧放置一个 detailTextLabel。然后,您可以将任何您想要的文本设置为适当的标签。

不过,为了回答您的问题,据我所知,同一标签的同一行中不可能有两种不同的文本对齐方式。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-11-28
    • 1970-01-01
    • 2019-07-03
    • 2020-02-08
    • 1970-01-01
    • 1970-01-01
    • 2016-12-30
    • 1970-01-01
    相关资源
    最近更新 更多