iosuitableviewuiimageviewpixelate

UIImageView in a custom UITableCiewCell dimensions and resolution


I'm trying to use a check mark in the UITablewViewCell which is a custom cell that has 3 labels. The problem is that no matter what resolution or dimensions I use for the check mark image, it's looks pixelated as in the image below. I tried 40x40, 60x60 and 80x80 pixels and also 72 Dpi and 300 Dpi with no success. Here is the code for the custom cell:

- (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;
}

And here is the screen shot: enter image description here


Solution

  • create two images named new_checkmark.png & new_checkmark@2x.png.

    new_checkmark@2x.png must be doubled dimension of new_checkmark.png in proportion.

    in coding dont use extension, onlu give name like this

       [cell.imageView setImage:[UIImage imageNamed:@"new_checkmark"]];