How to set image to UIImage

后端 未结 12 895
小蘑菇
小蘑菇 2020-12-14 06:20

How can I set image to UIImage object. For example:

UIImage *img = [[UIImage alloc] init];
[img setImage:[UIImage imageNamed:@\"anyImageName\"]]         


        
12条回答
  •  醉梦人生
    2020-12-14 07:16

    You can't alloc UIImage, this is impossible. Proper code with UIImageView allocate:

    UIImageView *_image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"something.png"]] ;
    

    Draw image:

    CGContextDrawImage(context, rect, _image.image.CGImage);
    

提交回复
热议问题