gpt4 book ai didi

ios - 多行 UILabel?

转载 作者:可可西里 更新时间:2023-11-01 03:39:33 25 4
gpt4 key购买 nike

我需要插入到 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。

最佳答案

试试这个:

CGSize labelsize;
UILabel *commentsTextLabel = [[UILabel alloc] init];
[commentsTextLabel setNumberOfLines:0];
[commentsTextLabel setBackgroundColor:[UIColor clearColor]];
NSString *text = @"yourtextString";
[commentsTextLabel setFont:[UIFont fontWithName:@"Helvetica"size:14]];
labelsize = [text sizeWithFont:commentsTextLabel.font
constrainedToSize:CGSizeMake(268, 2000.0)
lineBreakMode:UILineBreakModeWordWrap];
commentsTextLabel.frame = CGRectMake(10, 24, 268, labelsize.height);
[cell.contentView addSubview:commentsTextLabel];
[commentsTextLabel release];

关于ios - 多行 UILabel?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6070511/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com