我有一个表格 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/