objective-c - 如何减小字体大小并截断 ios tableview 中的文本标签

标签 objective-c ios

我有一个表格 View 。我想在 cell.detailTextLabel.text 中减小字体大小并将字符串的长度截断为 5 个字符。cud 你们帮帮我.. 下面是代码。

- (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) 
    {
        cell.detailTextLabel.text=@"Aktiviteter";
    }
    if (indexPath.row == 4)
    {
        cell.textLabel.textColor=[UIColor purpleColor];
        cell.detailTextLabel.text=@"Läs mer om Allegra";
    }
    if (indexPath.row == 5)
    {
        starImage.image = [UIImage imageNamed:@"add.png"];
        [cell.contentView addSubview:starImage];
    }

    return cell;
}

最佳答案

您可以通过设置小字体来减小 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;
}

关于objective-c - 如何减小字体大小并截断 ios tableview 中的文本标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9156445/

相关文章:

ios - 了解如何关闭 UIImagePickerController

ios - 在方法上计算给定数字会出现此错误

ios - 异步服务调用的 TableView 单元测试

某些客户的 iOS TCP 套接字失去连接

iOS OneSignalNotificationServiceExtension.appex : unknown error -1=ffffffffffffffff

iphone - 如何在音频播放器中为 iPhone 实现均衡器设置

iphone - 仪器中的红线

objective-c - 带 iOS 的 Linkedin SDK - 身份验证失败

HTMLReader 难以抓取视频链接

ios - CoreData : Cannot load NSManagedObjectModel. nil 是非法的URL参数