2012-07-17 64 views
0

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

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

回答

1

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

这是我的代码 - (的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]; 

}

+0

@ keyur bhalodiya不需要太多类型的代码只需要一个精确的代码。不要直接在这里复制粘贴。 – annu 2015-03-31 12:41:45

0

您应该可以通过更改框架来调整UILabel的大小。或者,使用adjustsFontSizeToFitWidth属性。请参阅文档:UILabel Documentation

+0

我做'[cell.textLabel SETFRAME:CGRectMake(0,0,10,30)]',但仍的UILabel到大。编辑:我登录的宽度和上面的代码我有一个320px宽度 – Edelweiss 2012-07-17 14:32:28

+0

也许你没有什么你认为你有。如果将宽度设置为10,宽度如何为320?我不明白你的意思。 – 2012-07-18 14:22:09

+0

你完全理解我的意思:)我将宽度设置为10,但是当我尝试将其记录到CONSOL日志中时,宽度设置为320!我发现了一个关于它的帖子,似乎这个标签不能调整大小(我现在没有链接)。 – Edelweiss 2012-07-18 15:04:45