我有一个视图,我在该视图上添加了文本和图像。我希望如果我添加一个图像,然后同时我也添加了下一个和下一个图像,但我有问题。当我在特定视图中移动一个图像时,其他图像也不会消失。
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
self.imageView.hidden =NO;
self.imageView .image = image;
[txtNotes addSubview:self.imageView];
[picker dismissViewControllerAnimated:YES completion:NULL];
}
答案 0 :(得分:1)
尝试此操作以在imagesView ....
上显示图像UIImageView *imageView;
NSArray *arrayOfImage=[[NSArray alloc]initWithObjects:@"i1.jpg",@"i2.jpg",@"i3.png", nil];;
float x=10;
float y=50;
float width=100;
float height=100;
int i=0;
for(i=0;i<[arrayOfImage count];i++)
{
imageView=[[UIImageView alloc]initWithFrame:CGRectMake(x+width*i, y, width, height)];
imageView.image=[UIImage imageNamed:[NSString stringWithFormat:@"%@",[arrayOfImage objectAtIndex:i]]];
[self.view addSubview:imageView];
}
else if(i==[arrayOfImage count])
{
i=0;
imageView.image=[UIImage imageNamed:[NSString stringWithFormat:@"%@",[arrayOfImage objectAtIndex:i]]];
[self.view addSubview:imageView];
i++;
}
如果你想在下一个按钮和后退按钮上更改我的图像...然后尝试下面的代码
- (IBAction)btnClicked:(id)sender
{
UIImageView *imageView;
NSArray *arrayOfImage=[[NSArray alloc]initWithObjects:@"i1.jpg",@"i2.jpg",@"i3.png",@"i1.jpg",@"i2.jpg",@"i3.png", nil];;
float x=100;
float y=100;
float width=100;
float height=100;
imageView=[[UIImageView alloc]initWithFrame:CGRectMake(x, y, width, height)];
if([sender tag]==0)
{
if(i<[arrayOfImage count])
{
imageView.image=[UIImage imageNamed:[NSString stringWithFormat:@"%@",[arrayOfImage objectAtIndex:i]]];
[self.view addSubview:imageView];
i++;
}
else if(i==[arrayOfImage count])
{
i=0;
imageView.image=[UIImage imageNamed:[NSString stringWithFormat:@"%@",[arrayOfImage objectAtIndex:i]]];
[self.view addSubview:imageView];
i++;
}
}else
{
if(i<[arrayOfImage count])
{
imageView.image=[UIImage imageNamed:[NSString stringWithFormat:@"%@",[arrayOfImage objectAtIndex:i]]];
[self.view addSubview:imageView];
i--;
}
else if(i==-1)
{
i=0;
imageView.image=[UIImage imageNamed:[NSString stringWithFormat:@"%@",[arrayOfImage objectAtIndex:i]]];
[self.view addSubview:imageView];
i++;
}
}
}
注意:将Tag to Next按钮设置为0并将tag设置为后退按钮为1。
答案 1 :(得分:0)
使用多个UIImageViews,在使用addSubview放置它们之前,设置一个框架,对于每个UIImageView都是不同的。
将多个图像放入一个UIImageView当然是可能的,但可能只有将图像合并为一个才能实现,我认为这不是最佳选择。怎么做,你可以在那里找到接受的答案: