1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- //
- // GuidePageView.m
- // ShangHaiShiKe
- //
- // Created by mac mini on 15/6/13.
- // Copyright (c) 2015年 翟玉磊. All rights reserved.
- //
- #import "GuidePageView.h"
- #define PAGEVIEW_WIDTH 100
- #define BACKBUTTON_WIDTH 95 //立即体验按钮的宽和高
- @implementation GuidePageView {
- NSArray * _images;
- }
- - (id)initWithFrame:(CGRect)frame images:(NSArray *)array {
- self = [super initWithFrame:frame];
- if (self) {
- _images = [NSArray arrayWithArray:array];
- [self initVIewUI]; //初始化
- }
- return self;
- }
- - (void)initVIewUI {
-
- //初始化空间
- mainScrollView = [[UIScrollView alloc] initWithFrame:self.bounds];
- [mainScrollView setContentSize:CGSizeMake(self.f_width * _images.count, mainScrollView.contentSize.height)]; //滚动范围
- [mainScrollView setDelegate:self];
- [mainScrollView setBackgroundColor:[UIColor clearColor]]; //背景颜色
- [mainScrollView setPagingEnabled:YES]; //是否整页滚动
- [mainScrollView setBounces:NO]; //遇到边框是否反弹
- [mainScrollView setShowsHorizontalScrollIndicator:NO]; //是否显示水平方向的滚动条
- [self addSubview:mainScrollView];
-
- //添加引导图
- for (int i = 0; i < _images.count; i++) {
- UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(self.f_width * i, 0, self.f_width, self.f_heigh)];
- imageView.contentMode = UIViewContentModeScaleAspectFit;
- [imageView setImage:[UIImage imageNamed:[_images objectAtIndex:i]]];
- [imageView setBackgroundColor:Color_White];
- [mainScrollView addSubview:imageView];
-
- //体验按钮
- if (i == _images.count - 1) {
- backBut = [UIButton buttonWithType:UIButtonTypeCustom];
- [backBut setFrame:CGRectMake(self.f_width * i, 0, self.f_width, self.f_heigh)];
- [backBut setBackgroundColor:[UIColor clearColor]];
- [backBut addTarget:self action:@selector(backButAction:) forControlEvents:UIControlEventTouchUpInside];
- [mainScrollView addSubview:backBut];
- }
- }
-
- pageView = [[UIPageControl alloc] initWithFrame:CGRectMake((SCREEN_WIDTH - PAGEVIEW_WIDTH)/2, SCREEN_HEIGHT - 30, PAGEVIEW_WIDTH,10)];
- pageView.numberOfPages = _images.count;
- pageView.currentPage = 0;
- [pageView setCurrentPageIndicatorTintColor:RGBA(150, 150, 150, 1)];
- [pageView setPageIndicatorTintColor:RGBA(134, 163, 87, 1)];
- // [self addSubview:pageView];
- }
- //点击事件
- - (void)backButAction:(id)sender {
- self->_GuidePageViewBack();
- }
- #pragma mark - UIScrollViewDelegate
- - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
- CGFloat page = floor((scrollView.contentOffset.x - scrollView.frame.size.width / 2) / scrollView.frame.size.width) + 1;
- pageView.currentPage = page;
- }
- /*
- // Only override drawRect: if you perform custom drawing.
- // An empty implementation adversely affects performance during animation.
- - (void)drawRect:(CGRect)rect {
- // Drawing code
- }
- */
- @end
|