2010-10-15 38 views
0

我有使用UITableViewCellStyleSubtitle顯示細胞的表:UICell爲textLabel改變幀大小

============================================================= 
Title:This is the title of something  Date:Custom label 
Subtitle:breif description 
============================================================= 

我的問題是,有時標題較長則該信元並覆蓋在所述日期。 所以有一種方法可以縮小cell.textlabel,以便它不會允許它覆蓋日期。

這裏是我的細胞

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

static NSString *CellIdentifier = @"Cell"; 



UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

if (cell == nil) { 
    cell = [[[UITableViewCell alloc] 
      initWithStyle:UITableViewCellStyleSubtitle 
      reuseIdentifier:CellIdentifier] 
      autorelease]; 

    CGRect frame; 

    if (self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft || self.interfaceOrientation == UIInterfaceOrientationLandscapeRight) 
     frame.origin.x = 370; 
    else 
     frame.origin.x = 220; 

    frame.origin.y = 15; 
    frame.size.height = 15; 
    frame.size.width = 80; 

    UILabel *dateLabel = [[UILabel alloc] initWithFrame:frame]; 
    dateLabel.tag = 1; 
    [cell.contentView addSubview:dateLabel]; 
    [dateLabel release]; 
} 


    Document *d = [documentList objectAtIndex:indexPath.row]; 

    UILabel *dateLabel = (UILabel *) [cell.contentView viewWithTag:1]; 
    dateLabel.text = [d date]; 
    dateLabel.textColor = [UIColor blackColor]; 
    [dateLabel setFont:[UIFont fontWithName:@"Arial" size:12]]; 

    cell.textLabel.textColor = [UIColor blackColor]; 
    [cell.textLabel setFont:[UIFont boldSystemFontOfSize:13]]; 
    cell.textLabel.text = [d title]; 

    cell.detailTextLabel.textColor = [UIColor blackColor]; 
    [cell.detailTextLabel setFont:[UIFont fontWithName:@"Arial" size: 10]]; 
    cell.detailTextLabel.text = [d inst]; 

    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 


return cell; 

}

回答

1

創建自己的自定義UITableViewCell子類,手動整理標籤的代碼。目前,您正在使用內置的單元格類型(UITableViewCellStyleSubtitle),然後將日期子視圖添加到該單元格中,從而將標題標籤放在您的權限範圍之外。