Scenery:
Upload some images to a NSArray
and show them in UIImageView
as is done in the photo gallery. But without the options to edit. Just view and switch to the side using the swipe gesture.
I made a code manually but did not get the desired end result.
Code I made:
#import "ViewController.h"
@interface ViewController (){
// Array para salvar imagens
NSArray* imagens;
//Imagens
UIImage* img1, *img2, *img3;
// ScrollView que fará a mudança
IBOutlet UIScrollView *scrollView;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
// Pegando as imagens
img1 = [UIImage imageNamed:@"acai11.jpg"];
img2 = [UIImage imageNamed:@"gloria4.jpg"];
img3 = [UIImage imageNamed:@"gloria5.jpg"];
// Alocando cada uma em uma posição no array
imagens = [[NSArray alloc] initWithObjects:img1,img2,img3, nil];
// Pegando as dimensões de scrollView e passando para tamanhoPagina
CGSize tamanhoPagina = scrollView.frame.size;
NSUInteger pagina = 0;
// Iniciando e posicionando uma imagem dentro do ScrollView
for (int i = 0; i < [imagens count]; i++)
{
// Criando um UIImgageView
UIImageView *imgView = [[UIImageView alloc] init];
// Passando o tamanho do scrollView para imagView, para que a imagem tenha o mesmo tamanho que o ScrollView
imgView.frame = CGRectMake(320*i, 0, 300, scrollView.frame.size.height);
imgView.image = [imagens objectAtIndex:i];
[scrollView addSubview:imgView];
imgView.frame = CGRectMake(tamanhoPagina.width * pagina ++ + 10, 0, tamanhoPagina.width - 20, tamanhoPagina.height);
}
scrollView.contentSize = CGSizeMake( scrollView.frame.size.width * imagens.count, scrollView.frame.size.height);
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
Below I will list the photos of the final result I want:
I believe there are native options for this task, and it is not complex or difficult to implement.
Any questions with the question just comment that I can add more information or provide details of the question.