Iphone 如何向页面控件添加视图
我是iPhone软件开发新手。请给我一些我可以在这里使用的代码。您可以创建Iphone 如何向页面控件添加视图,iphone,ios,scroll,uipagecontrol,Iphone,Ios,Scroll,Uipagecontrol,我是iPhone软件开发新手。请给我一些我可以在这里使用的代码。您可以创建UIViewControllers数组,如下所示 scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)]; scrollView.backgroundColor = [UIColor redColor]; scrollView.maximumZoomScale = 1.0; scrollView.minimumZoomScal
UIViewControllers
数组,如下所示
scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
scrollView.backgroundColor = [UIColor redColor];
scrollView.maximumZoomScale = 1.0;
scrollView.minimumZoomScale = 1.0;
scrollView.clipsToBounds = YES;
scrollView.showsHorizontalScrollIndicator = NO;
scrollView.pagingEnabled = YES;
self.view = scrollView;
pageControl = [[UIPageControl alloc] init];
pageControl.frame = CGRectMake(50, 350, 50, 50);
pageControl.numberOfPages = 3;
pageControl.currentPage = 0;
[self.view addSubview:pageControl];
然后只需添加ViewController或带有for循环的视图,如bellow
NSMutableArray *viewControllers;
NSMutableArray*控制器=[[NSMutableArray alloc]init];
for(无符号i=0;i<5;i++){
[控制器addObject:yourViewControlls];//使用不同的viewControls
}
self.viewControllers=控制器;
所以这里在数组中添加了5个viewConreoller,并在PageViewController中使用它
有关更多信息,请参阅本教程和示例
@Balveer使用此链接也希望对您有所帮助:)谢谢@paras joshi..我的页面控件并不是在每个页面上都能看到。我检查了很多我不理解的示例代码..我想做编程性的YUIVIEW*blueView=[[UIView alloc]init];blueView.frame=CGRectMake(100,0,500,1024);blueView.backgroundColor=[uicolorWithred:164.0/256绿色:176.0/256蓝色:224.0/256 alpha:1];[滚动视图添加子视图:蓝色视图];UIView*orangeView=[[UIView alloc]init];orangeView.frame=CGRectMake(700,05001024);orangeView.backgroundColor=[UIColor颜色与红色:252.0/256绿色:196.0/256蓝色:131.1/256 alpha:1];[滚动视图添加子视图:orangeView];嘿@Balveer刚刚阅读了教程,我在回答中发布了链接,而且非常简单,只要你在pagecontrols中添加你的视图数组,只要参考教程,你找到了关于它的代码,当我有空的时候,我也发布了代码dude.先生,如果你在我的网页上使用scrollview和uiview向我发送一个uipagecontrol的程序代码,我将不胜感激给巴尔维发邮件。isit@gmail.compossible副本
NSMutableArray *controllers = [[NSMutableArray alloc] init];
for (unsigned i = 0; i < 5; i++) {
[controllers addObject:yourViewControlls];// use different viewControls
}
self.viewControllers = controllers;
- (void)setupPage
{
UIView *blueView = [[UIView alloc] init];
blueView.frame = CGRectMake(0, 0, 640, 480);
blueView.backgroundColor = [UIColor whiteColor];
[scrollView addSubview:blueView];
self.pageControl.numberOfPages = 2;
[scrollView setContentSize:CGSizeMake(640, 0)];
}
- (void)scrollViewDidScroll:(UIScrollView *)_scrollView
{
if(pageControlIsChangingPage){
return;
}
CGFloat pageWidth = _scrollView.frame.size.width;
int page = floor((_scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
pageControl.currentPage = page;
}