ios – 添加图像进行查看

前端之家收集整理的这篇文章主要介绍了ios – 添加图像进行查看前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如何将图像添加到UIView?这是我到目前为止所尝试的:
UIView *imageHolder = [[UIView alloc] initWithFrame:CGRectMake(40,200,280,192)];
UIImage *image = [UIImage imageNamed:@"bloodymoon.jpg"];
[imageHolder addSubview:image]; // Error: Incompatible pointer types
[self.mainView addSubview:imageHolder];

解决方法

试试UIImageView:
UIImageView *imageHolder = [[UIImageView alloc] initWithFrame:CGRectMake(40,192)];
UIImage *image = [UIImage imageNamed:@"bloodymoon.jpg"];
imageHolder.image = image;
// optional:
// [imageHolder sizeToFit];
[self.mainView addSubview:imageHolder];
原文链接:https://www.f2er.com/iOS/335144.html

猜你在找的iOS相关文章