2015-01-08 128 views
0

我希望我的标签略微分开,并且有多行文本可用。UITableViewCell标签的显示不正确

Cell.m

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier 
{ 
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; 
    if (self) { 
     // Initialization code 
    } 
    return self; 
} 


- (void)layoutSubviews { 

    [super layoutSubviews]; 
    self.imageView.frame = CGRectMake(1,1,69,69); 
    float limgW = self.imageView.image.size.width; 
    if(limgW > 0) { 
     self.textLabel.frame = CGRectMake(74,self.textLabel.frame.origin.y,self.textLabel.frame.size.width,self.textLabel.frame.size.height); 
     self.detailTextLabel.frame = CGRectMake(74,self.detailTextLabel.frame.origin.y+self.textLabel.frame.size.height,self.detailTextLabel.frame.size.width,self.detailTextLabel.frame.size.height); 
    } 

} 

在控制器中,cellForRowAtIndexPath是:

- (UITableViewCell *)tableView:(UITableView *)tableView 
     cellForRowAtIndexPath:(NSIndexPath *)indexPath 
         object:(PFObject *)object 
{ 
    static NSString *CellIdentifier = @"Cell"; 

    Cell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[Cell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]; 
    } 


    // Configure the cell to show todo item with a priority at the bottom 
    cell.textLabel.text = object[@"Title"]; 
    cell.detailTextLabel.text = object[@"Request"]; 
    PFFile *thumbnail = object[@"ProfilePic"]; 
    cell.imageView.image = [UIImage imageNamed:@"[email protected]"]; 
    cell.imageView.file = thumbnail; 
    CALayer * l = [cell.imageView layer]; 
    [l setMasksToBounds:YES]; 
    [l setCornerRadius:36.7]; 
    [l setBorderWidth:2.0]; 
    [l setBorderColor:[[UIColor whiteColor] CGColor]]; 
    UIFont *cellFont = [UIFont fontWithName:@"Verdana-Bold" size:15]; 
    UIFont *cellFont2 = [UIFont fontWithName:@"Verdana-Bold" size:12]; 
    cell.textLabel.numberOfLines = 0; 
    cell.detailTextLabel.numberOfLines = 0; 
    cell.textLabel.font = cellFont; 
    cell.detailTextLabel.font = cellFont2; 
    cell.textLabel.textColor = [UIColor whiteColor]; 
    cell.detailTextLabel.textColor = [UIColor whiteColor]; 
    cell.backgroundColor = [UIColor blackColor]; 


    return cell; 
} 

怎么会2号线是越来越缩写,为什么是textLabeldetailTextLabel如此接近? enter image description here

+1

使用自定义标签** cell.detailTextLabel ** –

+0

看起来你想要一个真正自定义的单元格(你似乎已经在'Cell'中创建),但你仍然试图获得标准控件('textLa bel'和'detailTextLabel')来适合你的数据。相反,我建议对待你的新单元类,就好像你没有访问任何控件,只是自己创建你需要的单元。 – mbm29414

回答

0

尝试:

if(limgW > 0) { 
     self.textLabel.frame = CGRectMake(74,self.textLabel.frame.origin.y,self.textLabel.frame.size.width,self.textLabel.frame.size.height); 

     // change this two lines 
     self.detailTextLabel.frame = CGRectMake(74,self.detailTextLabel.frame.origin.y,self.detailTextLabel.frame.size.width,self.detailTextLabel.frame.size.height * 2); 
     self.detailTextLabel.numberOfLines = 2; 
    } 
1

使用自定义的UITableViewCell,

例如:在** ** cell.textLabel和地点

@interface CustomViewCell : UITableViewCell 

@property(nonatomic,weak)IBOutlet UIImageView *imageView; 
@property(nonatomic,weak)IBOutlet UILabel *titleView; 
@property(nonatomic,weak)IBOutlet UILabel *detailView; 

@end