我有一个表视图。我希望减少字体大小,并在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;
}
答案 0 :(得分: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;
}