我有一个自定义的tableViewCell。 questionContent是一个标签,我设置了numberOfLines = 0
和lineBreakMode = NSLineBreakMode.ByWordWrapping
但它没有换行。即使我设置了`numberOfLines = 0`,UILabel也不会换行
存在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)
但它不换行。这里是截图
也许ü错过标签的宽度约束?比如从正确的标签到屏幕的右边缘?或者你强迫标签高度也会导致这种情况发生 – Tj3n
我设置了'frame'。这是问题吗? – rose
您是否尝试过设置单元格的估计行高? '_tableView.rowHeight = UITableViewAutomaticDimension;''_tableView.estimatedRowHeight = 50;' –