Resize UIImageView in UITableViewCell

后端 未结 4 1216
暖寄归人
暖寄归人 2020-12-16 03:51

I have a 16x16 pixel image that I want to display in an UIImageView. So far, no problem, however 16x16 is a bit small so I want to resize the image view to 32x32 and thus al

4条回答
  •  借酒劲吻你
    2020-12-16 04:25

    I think you need to set the contentMode:

    cell.imageView.contentMode = UIViewContentModeScaleAspectFit;
    

    In context:

    UIImage *image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"slashdot" ofType:@"png"]];
    imageView = [[UIImageView alloc] initWithImage:image];
    [imageView setBackgroundColor:[UIColor greenColor]];
    [imageView setFrame:CGRectMake(x,y,32,32)];
    imageView.contentMode = UIViewContentModeScaleAspectFit;    
    [self.view addSubview:imageView];
    

    Note: I've set a background colour so you can debug the on-screen boundaries of the UIImageView. Also x and y are arbitrary integer coordinates.

提交回复
热议问题