我有一个图像视图,它在视图加载时随机生成图像,我想将第二个图像视图添加到同一个视图控制器。我以为我可以复制我的代码并更新属性,但它现在可以工作了。这是我的代码:
。H
#import <UIKit/UIKit.h>
@interface ImageViewViewController : UIViewController
@property (strong, nonatomic) IBOutlet UIImageView *imageView;
@end
.m
[super viewDidLoad];
int randomImages = rand() % 4;
switch (randomImages) {
case 0:
_imageView.image = [UIImage imageNamed:@"1.png"];
break;
case 1:
_imageView.image = [UIImage imageNamed:@"2.png"];
break;
case 2:
_imageView.image = [UIImage imageNamed:@"3.png"];
break;
case 3:
_imageView.image = [UIImage imageNamed:@"4.png"];
break;
}