2015-05-11 237 views
-2

我有一個視圖,我在該視圖上添加了文本和圖像。我希望如果我添加一個圖像,然後在同一時間我也添加下一個和下一個圖像,但我有問題。當我在該特定視圖中移動一個圖像時,其他圖像也不會消失。如何將多個圖像添加到圖像視圖

- (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]; 

} 

enter image description here

+0

檢查我的答案。我想你有任何圖像陣列..然後寫下面的代碼。 –

+0

你還沒有回覆。 –

+0

等我檢查@Asoke Londhe – SoftCoder

回答

0

試試這個對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++; 

    } 

} 


} 

注:設置標籤用於下一步按鈕爲0,並設置標籤,以後退按鈕,當1

0

使用多個的UIImageViews並將它們放置使用addSubview之前,將它們設置的幀,這將是對於每個不同的UIImageView。

將多個圖像放入一個UIImageView當然是可能的,但可能只有通過將圖像合併爲一個,我不會考慮最佳選擇。如何做到這一點,你可以接受的答案在那裏找到:

iOS - Merging two images of different size