2012-02-06 36 views
1

我有一個表view.i想減少字體大小和截斷字符串的長度爲5個字符cell.detailTextLabel.text .cud你們幫我。下面是代碼。如何減少字體大小和截斷文本標籤在ios tableview

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"Cell"; 
    //NSInteger SectionRows=[tableView1 numberOfRowsInSection:indexPath.section]; 
    //NSInteger Row=indexPath.row; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) 
    { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease]; 
    } 
    //cell.imageView.backgroundColor=[UIColor clearColor]; 
    cell.selectionStyle=UITableViewCellSelectionStyleNone; 
    cell.textLabel.text=[listOfItems objectAtIndex:indexPath.row]; 
    cell.textLabel.backgroundColor=[UIColor clearColor]; 
    cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator; 

    if (indexPath.row == 3) 
    { 
     [email protected]"Aktiviteter"; 
    } 
    if (indexPath.row == 4) 
    { 
     cell.textLabel.textColor=[UIColor purpleColor]; 
     [email protected]"Läs mer om Allegra"; 
    } 
    if (indexPath.row == 5) 
    { 
     starImage.image = [UIImage imageNamed:@"add.png"]; 
     [cell.contentView addSubview:starImage]; 
    } 

    return cell; 
} 

回答

2

您可以通過設置小字體來減少detailTextLabel的字體大小。您可以設置不同大小的一些不同的字體。

cell.detailTextLabel.font = [UIFont systemFontOfSize:([UIFont systemFontSize]-2)]; 

只顯示字符串的前5個字符,請執行以下操作:

NSString *text = @"Aktiviteter"; 
text = [text substringToIndex:5]; 
cell.detailTextLabel.text = text; 

因此,將它看起來像

if (indexPath.row == 3) { 
    cell.detailTextLabel.font = [UIFont systemFontOfSize:([UIFont systemFontSize]-2)]; 
    NSString *text = @"Aktiviteter"; 
    text = [text substringToIndex:5]; 
    cell.detailTextLabel.text = text; 
} 
+0

這個回答解決問題了嗎? – Ilanchezhian 2012-02-06 07:25:09

+0

感謝man dat工作.. – stephensam 2012-02-06 07:51:16