我会在我的视图的不同位置添加相同的UIImageView
。
所以我可以使用相同的图像制作十个UIImageViews
,但使用其他名称。但我得到了ca. 50 UIImageViews
。
我用这段代码创建了我的UIImageView:
代码:
CGRect dragRect = CGRectMake(0.0f, 0.0f, 70.0, 70.0);
dragRect.origin = CGPointMake(10, 300);
UIImageView *image = [[UIImageView alloc] initWithFrame:dragRect];
[image setImage:[UIImage imageNamed:@"Apple.png"]];
[self.view addSubview:image;
现在,我想更改dracRect.origin
点并使用其他名称制作新的UIImageView
。我会在for
循环中执行此操作。这可能吗?
代码:
int x;
for (x=0; x>=3; x=x+1) {
CGRect dragRect = CGRectMake(0.0f, 0.0f, 70.0, 70.0);
//x koordinate wird immer 10 grösser
dragRect.origin = CGPointMake(x*10, 300);
//image1, image2, image3
NSString *string1 = [[string1 alloc] initWithFormat:@"image%d",x];
UIImageView *string1 = [[UIImageView alloc] initWithFrame:dragRect];
[string1 setImage:[UIImage imageNamed:@"Apple.png"]];
[self.view addSubview:string1;
}
更新
我使用image%i
和image%d
尝试了但是我收到了错误:
'string1'的冲突类型
答案 0 :(得分:0)