我正在使用UITableView
动态单元格,使用“右侧细节”样式。但是当textLabel
具有高宽度时,他隐藏了detailLabel
。textLabel hidding detailLabel
我试图调整textLabel
的大小,但它似乎是不可取的。有没有办法做到这一点,同时避免子类UITableViewCell
或自己添加一些UILabel
类?
我正在使用UITableView
动态单元格,使用“右侧细节”样式。但是当textLabel
具有高宽度时,他隐藏了detailLabel
。textLabel hidding detailLabel
我试图调整textLabel
的大小,但它似乎是不可取的。有没有办法做到这一点,同时避免子类UITableViewCell
或自己添加一些UILabel
类?
在单元格中添加自定义标签。如果仍遇到问题,请增加单元格的高度。
这是我的代码 - (的UITableViewCell *)的tableView:(UITableView的*)的tableView的cellForRowAtIndexPath:(NSIndexPath *)indexPath { 静态的NSString * CellIdentifier = @ “小区”;
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];
}
您应该可以通过更改框架来调整UILabel
的大小。或者,使用adjustsFontSizeToFitWidth
属性。请参阅文档:UILabel Documentation
我做'[cell.textLabel SETFRAME:CGRectMake(0,0,10,30)]',但仍的UILabel到大。编辑:我登录的宽度和上面的代码我有一个320px宽度 – Edelweiss 2012-07-17 14:32:28
也许你没有什么你认为你有。如果将宽度设置为10,宽度如何为320?我不明白你的意思。 – 2012-07-18 14:22:09
你完全理解我的意思:)我将宽度设置为10,但是当我尝试将其记录到CONSOL日志中时,宽度设置为320!我发现了一个关于它的帖子,似乎这个标签不能调整大小(我现在没有链接)。 – Edelweiss 2012-07-18 15:04:45
@ keyur bhalodiya不需要太多类型的代码只需要一个精确的代码。不要直接在这里复制粘贴。 – annu 2015-03-31 12:41:45