我已经下载了 Gallery 示例代码,但我不知道如何使用它?它显示 12 张相同的图片,我想要不同的图片,我想要一个 imagesArray 而不是一张图片,我该怎么办?
以下是我的代码,
#import "ViewController.h"
#import "UIViewAnimationExplose.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.allViews = [[NSMutableArray alloc]init];
int numberColumn = 0;
int numberRaw = 0;
for (int i = 0; i < 12; i++) {
UIImageView *img = [[UIImageView alloc]initWithFrame:CGRectMake(10 + numberColumn * 252, 10 + numberRaw * 248, 242, 238)];
img.contentMode = UIViewContentModeScaleAspectFill;
img.clipsToBounds = YES;
img.userInteractionEnabled = YES;
img.image = [UIImage imageNamed:@"becomeapanda_tumblr_com"];
[self.view addSubview:img];
[self.allViews addObject:img];
numberColumn++;
if (numberColumn > 2) {
numberRaw++;
numberColumn =0;
}
}
self.exploseContainer = [[AnimationExploseContainer alloc] initWithViews:self.allViews];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
最佳答案
重命名您的图像,如 img1、img2..... img12,然后像这样修改您的代码,
for (int i = 0; i < 12; i++) {
UIImageView *img = [[UIImageView alloc]initWithFrame:CGRectMake(10 + numberColumn * 252, 10 + numberRaw * 248, 242, 238)];
img.contentMode = UIViewContentModeScaleAspectFill;
img.clipsToBounds = YES;
img.userInteractionEnabled = YES;
img.image = [UIImage imageNamed:[NSString stringWithFormat:@"img%d",i]];
[self.view addSubview:img];
[self.allViews addObject:img];
numberColumn++;
if (numberColumn > 2) {
numberRaw++;
numberColumn =0;
}
}
关于ios - 如何在以下代码中插入图像数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20946812/