Ios 自定义UITableCiewCell中的UIImageView尺寸和分辨率
我试图在UITablewViewCell中使用复选标记,这是一个具有3个标签的自定义单元格。问题是,无论我对复选标记图像使用何种分辨率或尺寸,它看起来都是像素化的,如下图所示。我尝试了40x40、60x60和80x80像素以及72 Dpi和300 Dpi,但都没有成功。以下是自定义单元格的代码:Ios 自定义UITableCiewCell中的UIImageView尺寸和分辨率,ios,uitableview,uiimageview,pixelate,Ios,Uitableview,Uiimageview,Pixelate,我试图在UITablewViewCell中使用复选标记,这是一个具有3个标签的自定义单元格。问题是,无论我对复选标记图像使用何种分辨率或尺寸,它看起来都是像素化的,如下图所示。我尝试了40x40、60x60和80x80像素以及72 Dpi和300 Dpi,但都没有成功。以下是自定义单元格的代码: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)index
- (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;
}
下面是屏幕截图:
创建两个名为new_checkmark.png和new的图像_checkmark@2x.png. 新的_checkmark@2x.png必须按比例将new_checkmark.png的维度加倍 在编码中,不要使用扩展名,只能这样命名
[cell.imageView setImage:[UIImage imageNamed:@"new_checkmark"]];
您是否使用视网膜图像进行视网膜显示?例如,应该有两个图像“new_checkmark.png”用于非视网膜和“new”_checkmark@2x.png“用于视网膜设备。此外,还应将UIImageView的帧设置为与图像大小成比例。