Created
April 26, 2012 19:12
-
-
Save emersonbroga/2502127 to your computer and use it in GitHub Desktop.
Emerson Carvalho.com >> iOS App: Criando um ScrollView (snippet 1)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Passo 1: Criar algumas variaveis uteis. | |
int screenWidth = self.view.bounds.size.width; //Largura da tela | |
int screenHeight = self.view.bounds.size.height;//Altura da Tela | |
int numberOfViews = 3; //Quantidade de views | |
//Passo 1: Criar o ScrollView | |
UIScrollView *scrollView = [[UIScrollView alloc]initWithFrame: CGRectMake(0, 0, screenWidth, screenHeight)]; | |
//Passo 2: Um loop para criar as views | |
for (int i=0; i<numberOfViews;i++) { | |
//Variável para a posicao de origem de cada view. | |
int viewOrigin = screenWidth * i; | |
//Criando a view | |
UIView *view = [[UIView alloc] initWithFrame: CGRectMake(viewOrigin, 0, screenWidth, screenHeight)]; | |
//Colocando o Background da View | |
[view setBackgroundColor: [UIColor colorWithRed:0.5/i green:0 blue:0 alpha:1]]; | |
//Adicionando a view no ScrollView. | |
[scrollView addSubview:view]; | |
//Removendo a view da memória | |
[view release]; | |
} | |
//Definindo o contentSize do ScrollView | |
[scrollView setContentSize: CGSizeMake( screenWidth * numberOfViews, screenHeight)]; | |
//Adicionando o ScrollView a View Principal | |
[self.view addSubview:scrollView]; | |
[scrollView release]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment