0

我正在使用UITableView带有“右细节”样式的动态单元格。但是当textLabel具有高宽度时,他隐藏了detailLabel.

我试图调整大小,textLabel但它似乎无法调整大小。有没有办法在避免子类化UITableViewCell或自己添加一些UILabel类的同时做到这一点?

4

2 回答 2

1

在单元格中添加自定义标签。如果仍然遇到问题,请增加单元格的高度。

这是我的代码 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] ;
cell.textLabel.textColor=[UIColor blackColor];
cell.backgroundColor=[UIColor clearColor];  
NSDictionary *dict=[dataArray objectAtIndex:indexPath.row];
NSString *strName=[dict objectForKey:@"name"];
NSString *strType = [dict objectForKey:@"type"];
cell.selectionStyle = NO;
cell.textLabel.numberOfLines=1;
cell.selectionStyle = UITableViewCellSelectionStyleBlue;
UILabel *lbl =[[UILabel alloc]init];
lbl.frame=CGRectMake(115,8,220,40);
lbl.text=strName;
lbl.textColor = [UIColor colorWithRed:74/255.0f green:64/255.0f blue:34/255.0f alpha:1.0];
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
    lbl.font = [UIFont boldSystemFontOfSize:17];
}
else
{
    lbl.font = [UIFont boldSystemFontOfSize:15];
}
lbl.baselineAdjustment=UIBaselineAdjustmentAlignCenters;
lbl.numberOfLines=1;
lbl.backgroundColor=[UIColor clearColor];

UILabel *lbl1 =[[UILabel alloc]init];
lbl1.frame=CGRectMake(115,35,220,40);
lbl1.text=strType;
lbl1.textColor = [UIColor colorWithRed:74/255.0f green:64/255.0f blue:34/255.0f alpha:1.0];
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
    lbl1.font = [UIFont boldSystemFontOfSize:17];
}
else
{
    lbl1.font = [UIFont boldSystemFontOfSize:15];
}
lbl1.baselineAdjustment=UIBaselineAdjustmentAlignCenters;
lbl1.numberOfLines=1;
lbl1.backgroundColor=[UIColor clearColor];


[[cell contentView] addSubview:lbl];
[[cell contentView] addSubview:lbl1];
return cell;

[cell release];
[CellIdentifier release];
[lbl release];

}

于 2012-07-18T06:40:35.593 回答
0

您应该能够UILabel通过更改框架来调整 a 的大小。或者,使用该adjustsFontSizeToFitWidth属性。查看文档:UILabel 文档

于 2012-07-17T14:16:13.777 回答