Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 文本标签隐藏细节标签_Iphone_Objective C_Ios5_Uitableview - Fatal编程技术网

Iphone 文本标签隐藏细节标签

Iphone 文本标签隐藏细节标签,iphone,objective-c,ios5,uitableview,Iphone,Objective C,Ios5,Uitableview,我使用的是UITableView,动态单元格使用“右细节”样式。但是当textLabel的宽度较大时,他会隐藏detailLabel 我试图调整文本标签的大小,但它似乎无法执行。在避免子类化UITableViewCell或自己添加一些UILabel类的同时,是否有办法做到这一点?您应该能够通过更改其框架来调整UILabel的大小。或者,使用adjustsFontSizeToFitWidth属性。请参阅文档:在单元格中添加自定义标签。如果仍然存在问题,请增加单元格高度 这是我的密码 -(UITab

我使用的是
UITableView
,动态单元格使用“右细节”样式。但是当
textLabel
的宽度较大时,他会隐藏
detailLabel


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

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

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

这是我的密码 -(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{ 静态NSString*CellIdentifier=@“Cell”


}

我确实这样做了
[cell.textLabel setFrame:CGRectMake(0,0,10,30)]
但是UILabel仍然很大。编辑:我记录了宽度,根据上面的代码,我有一个320px的宽度,也许你没有你认为你拥有的。当您将宽度设置为10时,宽度如何为320?我不明白你的意思。你完全明白我的意思:)我将宽度设置为10,但当我尝试将其登录到控制台日志时,宽度设置为320!我找到了一篇关于它的帖子,似乎这个标签无法调整大小(我现在没有链接)。@keyur bhalodiya不需要太多代码,只需要一个精确的代码。不要直接在这里复制粘贴。
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];