美文网首页
ios 轮播图

ios 轮播图

作者: 繁华落尽终是殇 | 来源:发表于2017-08-09 16:17 被阅读0次

    #import "ViewController.h"

    #import "oneViewController.h"

    @interface ViewController (){

    UIScrollView *theSceo;

    NSArray *theArr;

    UIPageControl *thePage;

    }

    @end

    @implementation ViewController

    - (void)viewDidLoad {

                [super viewDidLoad];

                self.view.backgroundColor = [UIColor whiteColor];

                //初始化滚动视图

           theSceo = [[UIScrollView alloc]initWithFrame:self.view.frame];

            //设置代理

         theSceo.delegate = self;

          //设置按页滚动

        theSceo.pagingEnabled = YES;

        //设置是否显示滚动条

        theSceo.showsHorizontalScrollIndicator = NO;

        //添加到视图

    [self.view addSubview:theSceo];

    theArr = @[@"1.jpeg",@"2.jpeg",@"3.jpeg",@"4.jpeg"];

    CGFloat x = 0.0

    theSceo.contentSize = CGSizeMake(x, self.view.frame.size.height);

    //初始化一个分页控制器

    thePage = [[UIPageControl alloc]initWithFrame:CGRectMake((self.view.frame.size.width)/2-30, self.view.frame.size.height/5*4, 60, 20)];

    //设置分页控制器个数

    thePage.numberOfPages = theArr.count;

    //设置分页控制器的 颜色

    thePage.pageIndicatorTintColor = [UIColor whiteColor];

    //社会化做分页控制器选中的颜色

    thePage.currentPageIndicatorTintColor = [UIColor redColor];

    //添加到视图

    [self.view addSubview:thePage];

    }

    //实现分页控制器与滚动视图的关联

    - (void)scrollViewDidScroll:(UIScrollView *)scrollView{

    thePage.currentPage = theSceo.contentOffset.x/self.view.frame.size.width;

    }

    -(void)tz{

    oneViewController *v1 = [oneViewController new];

    [self presentViewController:v1 animated:YES completion:^{

    }];

    }

    @end

    相关文章

      网友评论

          本文标题:ios 轮播图

          本文链接:https://www.haomeiwen.com/subject/emlqrxtx.html