GuidePageView.m 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. //
  2. // GuidePageView.m
  3. // ShangHaiShiKe
  4. //
  5. // Created by mac mini on 15/6/13.
  6. // Copyright (c) 2015年 翟玉磊. All rights reserved.
  7. //
  8. #import "GuidePageView.h"
  9. #define PAGEVIEW_WIDTH 100
  10. #define BACKBUTTON_WIDTH 95 //立即体验按钮的宽和高
  11. @implementation GuidePageView {
  12. NSArray * _images;
  13. }
  14. - (id)initWithFrame:(CGRect)frame images:(NSArray *)array {
  15. self = [super initWithFrame:frame];
  16. if (self) {
  17. _images = [NSArray arrayWithArray:array];
  18. [self initVIewUI]; //初始化
  19. }
  20. return self;
  21. }
  22. - (void)initVIewUI {
  23. //初始化空间
  24. mainScrollView = [[UIScrollView alloc] initWithFrame:self.bounds];
  25. [mainScrollView setContentSize:CGSizeMake(self.f_width * _images.count, mainScrollView.contentSize.height)]; //滚动范围
  26. [mainScrollView setDelegate:self];
  27. [mainScrollView setBackgroundColor:[UIColor clearColor]]; //背景颜色
  28. [mainScrollView setPagingEnabled:YES]; //是否整页滚动
  29. [mainScrollView setBounces:NO]; //遇到边框是否反弹
  30. [mainScrollView setShowsHorizontalScrollIndicator:NO]; //是否显示水平方向的滚动条
  31. [self addSubview:mainScrollView];
  32. //添加引导图
  33. for (int i = 0; i < _images.count; i++) {
  34. UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(self.f_width * i, 0, self.f_width, self.f_heigh)];
  35. imageView.contentMode = UIViewContentModeScaleAspectFit;
  36. [imageView setImage:[UIImage imageNamed:[_images objectAtIndex:i]]];
  37. [imageView setBackgroundColor:Color_White];
  38. [mainScrollView addSubview:imageView];
  39. //体验按钮
  40. if (i == _images.count - 1) {
  41. backBut = [UIButton buttonWithType:UIButtonTypeCustom];
  42. [backBut setFrame:CGRectMake(self.f_width * i, 0, self.f_width, self.f_heigh)];
  43. [backBut setBackgroundColor:[UIColor clearColor]];
  44. [backBut addTarget:self action:@selector(backButAction:) forControlEvents:UIControlEventTouchUpInside];
  45. [mainScrollView addSubview:backBut];
  46. }
  47. }
  48. pageView = [[UIPageControl alloc] initWithFrame:CGRectMake((SCREEN_WIDTH - PAGEVIEW_WIDTH)/2, SCREEN_HEIGHT - 30, PAGEVIEW_WIDTH,10)];
  49. pageView.numberOfPages = _images.count;
  50. pageView.currentPage = 0;
  51. [pageView setCurrentPageIndicatorTintColor:RGBA(150, 150, 150, 1)];
  52. [pageView setPageIndicatorTintColor:RGBA(134, 163, 87, 1)];
  53. // [self addSubview:pageView];
  54. }
  55. //点击事件
  56. - (void)backButAction:(id)sender {
  57. self->_GuidePageViewBack();
  58. }
  59. #pragma mark - UIScrollViewDelegate
  60. - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
  61. CGFloat page = floor((scrollView.contentOffset.x - scrollView.frame.size.width / 2) / scrollView.frame.size.width) + 1;
  62. pageView.currentPage = page;
  63. }
  64. /*
  65. // Only override drawRect: if you perform custom drawing.
  66. // An empty implementation adversely affects performance during animation.
  67. - (void)drawRect:(CGRect)rect {
  68. // Drawing code
  69. }
  70. */
  71. @end