我读过几篇关于这个主题的文章:UILabel - auto-size label to fit text? , Swift - Adjusting fontSize to fit the width of the layout (programmatically) , 和 http://www.raywenderlich.com/87975/dynamic-table-view-cell-height-ios-8-swift .看来我完全按照这些帖子的建议行事,但似乎行不通。 以下是目前我的模拟器显示的内容:
我已经正确地设置了约束,我认为并且我这样写了以下内容:
override func viewDidLoad() {
super.viewDidLoad()
tableView.rowHeight = UITableViewAutomaticDimension
tableView.estimatedRowHeight = 150
}
然后我写道:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! CathyTaskLogTableViewCell
cell.messageLabel.sizeToFit()
cell.messageLabel.text = "If you'd like to have more control over the way objects are synced, you can keep them in the local datastore until you are ready to save them yourself using saveInBackground. To manage the set of objects that need to be saved, you can again use a label. The fromPinWithName: method on PFQuery makes it easy to fetch just the objects you care about."
return cell
}
我已经将 lines
行设置为 0
,如下所示:
对于 label
,我设置了所有四个约束以及宽度和高度约束。我的约束是这样的:
但是,它并没有导致我的所有线条都显示出来。对于如何解决这个问题,有任何的建议吗?提前致谢!!!
最佳答案
您应该删除标签的高度并从标签的底部添加新的约束到表格 View 。这可能会解决您的问题。因为如果您添加标签的约束高度那么它将修复标签的高度如果您放置底部约束那么无论您的内容有多少,它都会从底部开始固定像素高度。
关于ios - 根据内容的大小调整文本标签的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34868643/