Edelweiss
Edelweiss

Reputation: 621

textLabel hidding detailLabel

I'm using a UITableView with dynamic cell using the "Right Detail" Style. But when the textLabel has high width he hides the detailLabel.

I've tried to resize the textLabel but it seems to be unresizable. Is there a way to do it while avoiding to subclass UITableViewCell or adding by myself some UILabel classes?

Upvotes: 0

Views: 190

Answers (2)

kb920
kb920

Reputation: 3089

Add custom label in cell.Increase height of cell if still face problem.

Here is my code - (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];

}

Upvotes: 1

Owen Hartnett
Owen Hartnett

Reputation: 5935

You should be able to resize a UILabel by changing its frame. Alternatively, use the adjustsFontSizeToFitWidth property. See the documentation: UILabel Documentation

Upvotes: 0

Related Questions