0

我正在尝试在 UITablewViewCell 中使用复选标记,这是一个具有 3 个标签的自定义单元格。问题是,无论我对复选标记图像使用什么分辨率或尺寸,它看起来都是像素化的,如下图所示。我尝试了 40x40、60x60 和 80x80 像素以及 72 Dpi 和 300 Dpi,但均未成功。这是自定义单元格的代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:   (NSIndexPath *)indexPath
    {

       static NSString *CellIdentifier = @"MyCell";

     //UILabel *mainLabel, *secondLabel, *thirdLabel;

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

cell.accessoryType = UITableViewCellAccessoryNone;


//Add the 3 labels

mainLabel = [[UILabel alloc] initWithFrame:CGRectMake(40.0, 5.0, 180.0, 21.0)];
mainLabel.tag = MAINLABEL_TAG;
//mainLabel.font = [UIFont systemFontOfSize:14.0];
//mainLabel.font = [UIFont fontWithName:@"Geeza Pro Bold" size:17.0];
mainLabel.font = [UIFont boldSystemFontOfSize:13];
mainLabel.textAlignment = UITextAlignmentLeft;
mainLabel.textColor = [UIColor blackColor];
mainLabel.highlightedTextColor = [UIColor whiteColor];
mainLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[cell.contentView addSubview:mainLabel];

secondLabel = [[UILabel alloc] initWithFrame:CGRectMake(40.0, 21.0, 190.0, 21.0)];
secondLabel.tag = SECONDLABEL_TAG;
//secondLabel.font = [UIFont systemFontOfSize:12.0];
//secondLabel.font = [UIFont fontWithName:@"Geeza Pro" size:15.0];
secondLabel.font = [UIFont systemFontOfSize:13];
secondLabel.textAlignment = UITextAlignmentLeft;
secondLabel.textColor = [UIColor darkGrayColor];
secondLabel.highlightedTextColor = [UIColor whiteColor];
secondLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[cell.contentView addSubview:secondLabel];

thirdLabel = [[UILabel alloc] initWithFrame:CGRectMake(240.0, 11.0, 70.0, 21.0)];
thirdLabel.tag = THIRDLABEL_TAG;
//thirdLabel.font = [UIFont systemFontOfSize:12.0];
//thirdLabel.font = [UIFont fontWithName:@"Geeza Pro Bold" size:17.0];
thirdLabel.font = [UIFont boldSystemFontOfSize:13];
thirdLabel.textAlignment = UITextAlignmentRight;
thirdLabel.textColor = [UIColor blackColor];
thirdLabel.highlightedTextColor = [UIColor whiteColor];
thirdLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[cell.contentView addSubview:thirdLabel];


}
    else
   {
        mainLabel = (UILabel *)[cell.contentView viewWithTag:MAINLABEL_TAG];
        secondLabel = (UILabel *)[cell.contentView viewWithTag:SECONDLABEL_TAG];
        thirdLabel = (UILabel *)[cell.contentView viewWithTag:THIRDLABEL_TAG];
    }

//If the requesting table view is the search display controller's table view, configure the cell using the filtered content, otherwise use the main list.

Car *car = nil;
if (tableView == self.searchDisplayController.searchResultsTableView)
{
     car = [self.filteredListContent objectAtIndex:indexPath.row];
 }
 else
 {
      car = [self.listContent objectAtIndex:indexPath.row];
  }


NSString *carName = [NSString stringWithFormat:@"%@",car.deviceName];
NSString *carDetails = [NSString stringWithFormat:@"%@ at %@",car.date,car.location];
NSString *carSpeed = [NSString stringWithFormat:@"%@ km/h",car.speed];


mainLabel.text = carName;
secondLabel.text = carDetails;
thirdLabel.text = carSpeed;

//Check for selection
if (car.isSelected == YES)
{
   [cell.imageView setImage:[UIImage imageNamed:@"new_checkmark.png"]];
}
else
{
   [cell.imageView setImage:nil];
}

return cell;
}

这是屏幕截图: 在此处输入图像描述

4

1 回答 1

1

创建两个名为 new_checkmark.png 和 new_checkmark@2x.png 的图像。

new_checkmark@2x.png 必须是 new_checkmark.png 的两倍尺寸。

在编码中不要使用扩展名,onlu 给出这样的名称

   [cell.imageView setImage:[UIImage imageNamed:@"new_checkmark"]];
于 2013-05-23T11:37:54.910 回答