【发布时间】:2016-03-12 04:49:58
【问题描述】:
我在表格单元格中添加了两个标签,顶部为左对齐,底部为右对齐,但文本显示不正确。
我在情节提要中为 tableview 添加了适当的约束,但这并没有解决问题。这是我用来设置标签的代码和生成的屏幕截图,我只是将边框用于调试目的
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath)
var label1 = UILabel(frame: CGRectMake(0,0, cell.bounds.width, cell.bounds.height/3))
var label2 = UILabel(frame: CGRectMake(0,cell.bounds.height/3, cell.bounds.width, cell.bounds.height/3 * 2))
label1.textAlignment = .Left
label1.text = "AAAA"
label1.layer.borderColor = UIColor.blackColor().CGColor
label1.layer.borderWidth = 1.0
label2.textAlignment = .Right
label2.text = "BBBB"
label2.layer.borderColor = UIColor.redColor().CGColor
label2.layer.borderWidth = 1.0
cell.addSubview(label1)
cell.addSubview(label2)
编辑:添加新图片以显示约束
【问题讨论】:
-
请发布您的限制条件
-
添加新图片以发布@EICaptain
标签: swift autolayout uilabel constraints tableviewcell