UITableViewCell上2个UILabel的布局

问题描述 投票:0回答:1

我希望在自定义表格视图单元格上有2个标签。第一个标签应该在距左边距15磅的左侧,第二个标签应该在右边距距右边15磅的磅。它可以在内部增长。由于标签不会显示大量数据,因此标签之间肯定不会重叠。

我正在使用堆栈视图。以下是我的自定义xib文件的图像。两个标签的行数均设置为1。启动时,我看到一个没有标签的空白单元格。缺少什么?

enter image description here

enter image description here

enter image description here

enter image description here

EDIT:添加更多详细信息。我更新了UIStackView上的分发以平等地填充,并更新了第二个标签的对齐方式,即开始时间标签在右边。我现在在单元格上看到数据,但是第二个标签未正确对齐。

enter image description here

enter image description herecellForRow中的代码:

let cell = tableView.dequeueReusableCell(withIdentifier: "displayStartTime") as! ScheduleDisplayStartTimeCustomCell
cell.selectionStyle = UITableViewCell.SelectionStyle.gray
cell.titleLabel.text = "Start"
cell.timeLabel.text = startTime
return cell

编辑后的外观如下:

enter image description here

ios swift uitableview uistackview
1个回答
0
投票

过去我遇到过类似的问题,我找到的最佳解决方案是将BackgroundColor分配给标签(蓝色,红色)和StackView(黑色)。然后,我看问题是否出在约束或UILabel文本对齐属性上。

此外,我注意到您对UIViews进行了扩展,其中可能存在引起问题的内容。

© www.soinside.com 2019 - 2024. All rights reserved.