2015-01-08 164 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