我正在使用动态单元格UITableView
使用“右侧细节”样式。但是当textLabel
宽度较高时,他会隐藏detailLabel
。
我试图调整textLabel
的大小,但似乎无法调整。有没有办法做到这一点,同时避免继承UITableViewCell
或自己添加一些UILabel
类?
答案 0 :(得分: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];
}
答案 1 :(得分:0)
您应该可以通过更改其框架来调整UILabel
的大小。或者,使用adjustsFontSizeToFitWidth
属性。请参阅文档:UILabel Documentation