多行 UILabel?
我需要插入 UILabel
多行文本。我执行以下操作:
NSMutableString * spName = [[NSMutableString alloc ]initWithString:@""];
for (NSUInteger i=0; i<arrEx.count; ++i)
{
ExInfo * exInf = [arrEx objectAtIndex:i];
[spName appendString:[MyObject getName:exInf.spNum]];
[spName appendString:@" "];
[spName appendString:exInf.totalTime];
[spName appendString:@"\n"];
}
CGSize size = [spName sizeWithFont:[UIFont systemFontOfSize:14]
constrainedToSize:constraint
lineBreakMode:UILineBreakModeWordWrap];
[cell.exsInfoLabel setFrame:CGRectMake(CELL_CONTENT_MARGIN, top, CELL_CONTENT_WIDTH - (CELL_CONTENT_MARGIN * 2), size.height)];
[cell.exsInfoLabel setText:spName];
[spName release];
arrEx
由两个项目组成,因此它应该是两个字符串。但 UITableViewCell
仅包含第一个字符串。 在 IB 中,我将 UILabel cell.exsInfoLabel 的行数设置为 0。
I need insert to UILabel
multiline text. I do the following:
NSMutableString * spName = [[NSMutableString alloc ]initWithString:@""];
for (NSUInteger i=0; i<arrEx.count; ++i)
{
ExInfo * exInf = [arrEx objectAtIndex:i];
[spName appendString:[MyObject getName:exInf.spNum]];
[spName appendString:@" "];
[spName appendString:exInf.totalTime];
[spName appendString:@"\n"];
}
CGSize size = [spName sizeWithFont:[UIFont systemFontOfSize:14]
constrainedToSize:constraint
lineBreakMode:UILineBreakModeWordWrap];
[cell.exsInfoLabel setFrame:CGRectMake(CELL_CONTENT_MARGIN, top, CELL_CONTENT_WIDTH - (CELL_CONTENT_MARGIN * 2), size.height)];
[cell.exsInfoLabel setText:spName];
[spName release];
arrEx
consists of two items, so it should be two strings. But the UITableViewCell
contains only the first string.
In IB I set count of lines to 0 for the UILabel cell.exsInfoLabel
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

试试这个:
try this: