【发布时间】:2015-12-21 07:24:01
【问题描述】:
我有一个自定义的tableViewCell。 questionContent 是我设置的标签:
numberOfLines = 0
lineBreakMode = NSLineBreakMode.ByWordWrapping
但它不换行。
这是questionContent标签:
let questionContent: UILabel = {
let tempView = UILabel()
tempView.numberOfLines = 0
tempView.font = UIFont.systemFontOfSize(15)
tempView.lineBreakMode = NSLineBreakMode.ByWordWrapping
tempView.backgroundColor = UIColor.redColor()
return tempView
}()
在layoutSubviews()我设置了它的框架
//questionContent
let questionContentX = avatorImageX
let questionContentY = CGRectGetMaxY(avatorImage.frame) + answeModel!.marginTopBottomLeftOrRight
let questionContentWidth = kScreenWidth - answeModel!.marginTopBottomLeftOrRight * 2
let questionContentHeight = answeModel!.contentRealSize.height
questionContent.frame = CGRectMake(questionContentX, questionContentY, questionContentWidth, questionContentHeight)
questionContent.text = "Ssddfghjj ssddfghjjkk sssssffhjjk sasdfgghjjjkkllljhhgggggffdddssssaaaasfghjkkllnnvcczzzeefggghjjkkkklllkjhggtrrrddssdfcvvvxxcbbb"questionContent.frame 的第一个数据是 (8.0, 46.0, 304.0, 84.0),但它不会换行。这是截图
【问题讨论】:
-
也许你错过了标签的宽度限制?喜欢从右标签到屏幕右边缘?或者你强制标签高度也会导致这种情况发生
-
我设置了
frame。这是问题吗? -
您是否尝试过设置单元格的估计行高?
_tableView.rowHeight = UITableViewAutomaticDimension;_tableView.estimatedRowHeight = 50; -
不,我没有设置估计的行高。
-
请检查“layoutSubviews”方法是否被调用。