无法让 UILabel 显示超过 3 行
我有一个包含一堆单元格的 tableivew,我试图让 uilabel 显示超过 3 行。 我适当地设置了换行模式和行数,但它仍然没有显示超过三行。 有什么建议么? 表格单元格自动调整其高度以适应字符/行数,但文本显示三行,然后是一个椭圆(当您单击单元格时,它会转到另一个显示全文的视图。
下面是我的代码创建和显示 UILabel:
self.commentLabel = [self newLabelWithPrimaryColor:[UIColor blackColor] selectedColor:[UIColor whiteColor] fontSize:12.0 bold:YES];
self.commentLabel.textAlignment = UITextAlignmentLeft; // default
self.commentLabel.lineBreakMode = UILineBreakModeWordWrap;
self.commentLabel.numberOfLines = 0; // no limit to the number of lines
[myContentView addSubview:self.commentLabel];
[self.commentLabel release];
我希望整个评论显示在表格单元格中。
I have a tableivew with a bunch of cells and I am trying to get the uilabel to display more than 3 lines. I set the linebreakmode and the numberoflines appropriately, but it's still not displaying more than three lines. Any suggestions? The table cell automatically adjusts its height to accomodate the number of chars/lines, but the text shows three lines and then an ellipse (when you click the cell it goes to another view which shows the full text.
Below is the code that I have to create and display the UILabel:
self.commentLabel = [self newLabelWithPrimaryColor:[UIColor blackColor] selectedColor:[UIColor whiteColor] fontSize:12.0 bold:YES];
self.commentLabel.textAlignment = UITextAlignmentLeft; // default
self.commentLabel.lineBreakMode = UILineBreakModeWordWrap;
self.commentLabel.numberOfLines = 0; // no limit to the number of lines
[myContentView addSubview:self.commentLabel];
[self.commentLabel release];
I would like the entire comment to be displayed in the table cell.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
似乎标签的矩形太小,无法容纳所有文本...您必须使矩形更大,才能使其不显示省略号并显示整个文本
Seems like the rectangle of the label is too small to fit all the text...You must make the rectangle bigger in order for it to not display the ellipses and display the whole text
采用autolayout设计理念,不为UILabel设置高度限制,设置no。 行数为 0。
自动布局根据标签文本自动处理标签的动态高度。 如果标签具有单行文本,那么它将仅占用单行空间。 如果标签有多于一行,那么它将根据文本大小和显示文本所需的行数调整标签大小。
UITableViewAutomaticDimension
分配给 rowHeight 和 delegate estimatedRowHeightheightForRowAt
并返回一个值UITableViewAutomaticDimension
)-
目标 C:
看这个答案:在 UITableViewCell 内动态调整 UILabel?
With autolayout design concept, do not set height constraints for UILabel and set no. of lines as 0.
Autolayout automatically take care of dynamic height of label according to text of label. If label has single line text then it will occupy single line space only. And if label has more than one line then it will resize label according to text size and number of lines required to display text.
UITableViewAutomaticDimension
to rowHeight & estimatedRowHeightheightForRowAt
and return a valueUITableViewAutomaticDimension
to it)-
Objective C:
Look at this answer: Adjust UILabel Dynamically Within UITableViewCell?