似乎无法用UIImage和UITableViewCell的内容视图来解决这个问题

时间:2021-03-18 21:08:25

I need my cell's image view to have an area of 44x44 pixels so that it can be tapped. However, when I tried doing that, my 26x26 image got scaled to 44x44 without my permission, so now my 26x26 image is huge and blurry. I need to keep the 26x26 image at 26x26 but also increase the imageView frame to 44x44. This is what I've done but it hasn't worked:

我需要我的单元格的图像视图具有44x44像素的区域,以便可以点击它。然而,当我尝试这样做时,我的26x26图像在未经我许可的情况下被缩放到44x44,所以现在我的26x26图像非常模糊。我需要将26x26图像保持在26x26,但也将imageView帧增加到44x44。这就是我所做的,但它没有奏效:

//UITableViewCell subclass method

- (void) layoutSubviews {
    [super layoutSubviews];
    self.imageView.frame = CGRectMake(0, 0, 44.0, 44.0);
    self.imageView.contentMode = UIViewContentModeScaleAspectFit;
}

//TableView method    
-(void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath {
 UIImage *originalImage = [UIImage imageNamed:@"unchecked.png"];
 CGRect screenRect = CGRectMake(0, 0, 26.0, 26.0);
 UIGraphicsBeginImageContext(screenRect.size);
 [originalImage drawInRect:screenRect];
 cell.imageView.image = UIGraphicsGetImageFromCurrentImageContext();
 UIGraphicsEndImageContext(); 
}

1 个解决方案

#1


2  

Try setting the content mode to centre:

尝试将内容模式设置为居中:

self.imageView.contentMode = UIViewContentModeCenter;

#1


2  

Try setting the content mode to centre:

尝试将内容模式设置为居中:

self.imageView.contentMode = UIViewContentModeCenter;