2010-10-15 2 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), а затем добавляете к нему свое представление даты, которое помещает ярлык заголовка из вашего поля.

Смежные вопросы