Loading

Sunday, June 13, 2010

PageControl Without Application Delegates

1---> Create A Scroll View With Array Of Views
Each View's Dimension is 320x420
2---> in viewDidLoad ->
Arr_Element=[[NSMutableArray alloc]initWithObjects:@"First",@"Second",@"Third",@"Fourth",nil];
Arr_Count=[Arr_Element count]; //Arr_Count-> int
[Scrl setContentSize:CGSizeMake(Arr_Count*320,Scrl.bounds.size.height)];
pageControl.numberOfPages = Arr_Count;
pageControl.currentPage = 0;
for(int i=0;i {

UIView *Page_View=[[UIView alloc]initWithFrame:CGRectMake(i*320, 0, 320,420)];
UILabel *Lbl=[[UILabel alloc]initWithFrame:CGRectMake(10,10,300, 50)];
Lbl.text=[NSString stringWithFormat:@"%@",[Arr_Element objectAtIndex:i]];
Page_View.backgroundColor=[UIColor blueColor];
[Page_View addSubview:Lbl];
[Scrl addSubview:Page_View];
[Page_View release];
[Lbl release];
}

3---> - (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGFloat pageWidth = Scrl.frame.size.width;
int page = floor((Scrl.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
pageControl.currentPage = page;
pageControl.frame=CGRectMake(Scrl.contentOffset.x,415,320, 36);
}

4---> - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
pageControl.currentPage = (int)Scrl.contentOffset.x/320;
pageControl.frame=CGRectMake((int)Scrl.contentOffset.x,415,320, 36);
}

5---> -(void)Change:(id)sender
{
[Scrl scrollRectToVisible:CGRectMake(320*pageControl.currentPage, 0,320, 420) animated:YES];
}
6---> And Refer Change Method With PageControl-> Value Change

No comments:

Post a Comment