gpt4 book ai didi

iphone - UILabels 完整文本不可见

转载 作者:行者123 更新时间:2023-12-03 20:27:35 28 4
gpt4 key购买 nike

我必须在 UITableView 的单元格中并排放置两个 UILabels(state,zipCode),即 California 32320。当字体大小较小时,我可以清楚地看到它们。当我增加字体大小时,我看不到州的最后一个字母正在添加标签和 zipCode 标签。这是我正在处理的代码:

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

static NSString *CellIdentifier=@"Cell";

UITableViewCell* cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if(cell == nil)
{
cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]autorelease];

state=[[UILabel alloc] initWithFrame:CGRectZero];
state.tag = 116;
state.backgroundColor = [UIColor clearColor];
[state setFont:[UIFont fontWithName:@"Helvetica-Bold" size:12]];
[state setLineBreakMode:UILineBreakModeWordWrap];
[cell addSubview:state];


zipCode=[[UILabel alloc] initWithFrame:CGRectZero];
zipCode.tag = 121;
zipCode.backgroundColor = [UIColor clearColor];
[zipCode setFont:[UIFont fontWithName:@"Helvetica-Bold" size:12]];
[zipCode setLineBreakMode:UILineBreakModeWordWrap];
[cell addSubview:zipCode];

}

NSString *state1=[d objectForKey:@"State"];
CGSize constraint6=CGSizeMake(175,2000.0f);
CGSize size6=[state1 sizeWithFont:[UIFont fontWithName:@"Helvetica" size:12] constrainedToSize:constraint6 lineBreakMode:UILineBreakModeWordWrap];
state=(UILabel *)[cell viewWithTag:116];
state.frame=CGRectMake(105, city.frame.size.height+city.frame.origin.y+5, size6.width, 10);
[state setTextAlignment:UITextAlignmentLeft];

[state setText:[d valueForKey:@"State"]];

NSString *zip = [d objectForKey:@"Zip"];

if([zip isEqualToString:@""])
{

zipCode=[[UILabel alloc]initWithFrame:CGRectMake(105, 125, 320,10)];
zipCode .font=[UIFont fontWithName:@"Helvetica" size:12];
[zipCode setTextAlignment:UITextAlignmentLeft];
zipCode.hidden=YES;
[zipCode release];


}
else
{

NSString *zip=[d objectForKey:@"Zip"];
CGSize constraint200=CGSizeMake(175,2000.0f);
CGSize size200=[zip sizeWithFont:[UIFont fontWithName:@"Helvetica" size:12] constrainedToSize:constraint200 lineBreakMode:UILineBreakModeWordWrap];
zipCode=(UILabel *)[cell viewWithTag:121];
zipCode.frame=CGRectMake(13+state.frame.size.width+state.frame.origin.x, city.frame.size.height+city.frame.origin.y+5, size200.width,10);

[zipCode setTextAlignment:UITextAlignmentLeft];
[zipCode setText:[d valueForKey:@"Zip"]];
zipCode.numberOfLines=0;



}

return cell;
}

现在我可以看到结果为加利福尼亚州 32320

但是当我将字体大小减小到 10 时,我可以清楚地看到它们(加利福尼亚州 32320)。但是我只需要按照我的要求将字体大小设置为 12。

我哪里出错了?

最佳答案

使用此代码,它将看到标签适合您的标签尺寸

label.adjustsFontSizeToFitWidth = YES;

关于iphone - UILabels 完整文本不可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14118208/

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