2012-02-16 5 views
0

私はいくつかのテーブルでアプリを手に入れました。cell.textLabelを短くしましょう

この表には、タイトルがtextLabel、日付がdetailTextLabelの2つのラベルがあります。しかし、タイトルが本当に長い場合は、detailTextLabelを超えて表示されます。

どうすればこの問題を解決できますか?

P.S.
私はこのようにlayoutSubviews方法上書きしようとした:

- (void)layoutSubviews { 
    [super layoutSubviews]; 

    CGSize size = self.bounds.size; 
    CGRect frame = CGRectMake(4.0f, 4.0f, size.width, size.height); 
    self.textLabel.frame = frame; 
    self.textLabel.contentMode = UIViewContentModeScaleAspectFit; 
} 

をしかし、それは

+1

あなたはcell.textLabel.numberOfRows = 1を試してみましたか? – Hiren

+0

あなたがnumberOfLinesを意味するなら - それはあまりにも効き目がありません。その前に –

答えて

1

まず、私は空のセルを作成して動作しません。次に、UILabelをタグ付きのsubViewとして追加します。そして、UILabelのフレームを変更してください。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"Recent Dream"; 

    UITableViewCell *cell;// = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

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

     NSLog(@"new cell"); 

     UILabel *textLabel = [[UILabel alloc] init]; 
     textLabel.frame = CGRectMake(10, 0, self.view.frame.size.width -110, 48); 
     textLabel.backgroundColor = [UIColor clearColor]; 
     textLabel.font = [UIFont boldSystemFontOfSize:16]; 
     [textLabel setTag:1]; 
     [cell.contentView addSubview:textLabel]; 
    } 

    // Configure the cell... 

    Dream *tempDream = [self.dreams objectAtIndex:indexPath.row]; 

    NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; 
    [formatter setDateFormat:@"MM/dd/yyyy"]; 

    //Optionally for time zone converstions 
    [formatter setTimeZone:[NSTimeZone timeZoneWithName:@"..."]]; 

    NSString *stringFromDate = [formatter stringFromDate:tempDream.dateAdd]; 

    UIColor *background = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"bodyWrapper.png"]]; 

    cell.contentView.backgroundColor = background; 

    UILabel *textLabel = (UILabel *)[cell.contentView viewWithTag:1]; 

    textLabel.text = tempDream.title; 

    cell.textLabel.text = @""; 
    cell.detailTextLabel.text = stringFromDate; 

    return cell; 
} 
0
float newWidth = 30; //to try increase the value, while all will be right. 
CGRect frame = CGRectMake(4.0f, 4.0f, size.width - newWidth, size.height); 
+0

私はsize.widthを数字に置き換えようとしました。問題を解決していない=( –

関連する問題