《省钱达人》与《猎豆优选》UI相同版。域名tbk

XTGuidePagesViewController.m 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. //
  2. // XTGuidePagesViewController.m
  3. // XTGuidePagesView
  4. //
  5. // Created by zjwang on 16/5/30.
  6. // Copyright © 2016年 夏天. All rights reserved.
  7. //
  8. #import "XTGuidePagesViewController.h"
  9. #define s_w [UIScreen mainScreen].bounds.size.width
  10. #define s_h [UIScreen mainScreen].bounds.size.height
  11. @interface XTGuidePagesViewController ()<UIScrollViewDelegate>
  12. @property (nonatomic, strong) UIPageControl *pageControl;
  13. @end
  14. @implementation XTGuidePagesViewController
  15. - (void)guidePageControllerWithImages:(NSArray *)images AndTitle:(NSArray *)titles Andtipe:(NSArray *)tipes
  16. {
  17. UIScrollView *gui = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, s_w, s_h)];
  18. gui.delegate = self;
  19. gui.pagingEnabled = YES;
  20. // 隐藏滑动条
  21. gui.showsHorizontalScrollIndicator = NO;
  22. gui.showsVerticalScrollIndicator = NO;
  23. // 取消反弹
  24. gui.bounces = NO;
  25. for (NSInteger i = 0; i < images.count; i ++) {
  26. [gui addSubview:({
  27. self.btnEnter = [UIButton buttonWithType:UIButtonTypeCustom];
  28. self.btnEnter.frame = CGRectMake(s_w * i, 0, s_w, s_h);
  29. [self.btnEnter setImage:[UIImage imageNamed:images[i]] forState:UIControlStateNormal];
  30. UIImageView *img =[[UIImageView alloc]initWithFrame:CGRectMake( FITSIZE(10), (SCREEN_HEIGHT-s_w+FITSIZE(20))/2-FITSIZE(60), s_w-FITSIZE(20), s_w-FITSIZE(20))];
  31. img.image =[UIImage imageNamed:[NSString stringWithFormat:@"ydy-%d",i+1]];
  32. [self.btnEnter addSubview:img];
  33. UILabel *label1 =[[UILabel alloc]initWithFrame:CGRectMake(0, (SCREEN_HEIGHT-s_w-FITSIZE(30))/2+s_w-FITSIZE(20), SCREEN_WIDTH, FITSIZE(30))];
  34. label1.text=titles[i];
  35. label1.textColor=[UIColor whiteColor];
  36. [self.btnEnter addSubview:label1];
  37. if (@available(iOS 8.2, *)) {
  38. label1.font =[UIFont systemFontOfSize:FITSIZE(30) weight:FITSIZE(1)];
  39. } else {
  40. label1.font =[UIFont systemFontOfSize:FITSIZE(30)];
  41. }
  42. label1.textAlignment=NSTextAlignmentCenter;
  43. UILabel *label =[[UILabel alloc]initWithFrame:CGRectMake(0, (SCREEN_HEIGHT-s_w+FITSIZE(60))/2+s_w-FITSIZE(20), SCREEN_WIDTH, FITSIZE(30))];
  44. label.text=tipes[i];
  45. label.textColor=[UIColor whiteColor];
  46. label.font =[UIFont systemFontOfSize:FITSIZE(24)];
  47. label.textAlignment=NSTextAlignmentCenter;
  48. [self.btnEnter addSubview:label];
  49. self.btnEnter;
  50. })];
  51. [self.btnEnter addSubview:({
  52. UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
  53. if (i == images.count - 1) {
  54. [btn setTitle:@"马上体验" forState:UIControlStateNormal];
  55. btn.hidden =NO;
  56. }else{
  57. btn.hidden=YES;
  58. }
  59. btn.highlighted=NO;
  60. btn.frame = CGRectMake(s_w * i, s_h - 65, 130, 40);
  61. btn.center = CGPointMake(s_w / 2, s_h - 5-TabbarHeight);
  62. btn.layer.cornerRadius = 4;
  63. btn.clipsToBounds = YES;
  64. [btn setTitleColor:[UIColor homeRedColor] forState:UIControlStateNormal];
  65. btn.backgroundColor = [UIColor whiteColor];
  66. [btn addTarget:self action:@selector(clickEnter) forControlEvents:UIControlEventTouchUpInside];
  67. btn;
  68. })];
  69. }
  70. gui.contentSize = CGSizeMake(s_w * images.count, 0);
  71. [self.view addSubview:gui];
  72. // pageControl
  73. self.pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(0, 0, s_w / 2, 30)];
  74. self.pageControl.center = CGPointMake(s_w / 2, s_h - BottomMargin-15);
  75. [self.view addSubview:self.pageControl];
  76. self.pageControl.numberOfPages = images.count;
  77. }
  78. - (void)clickEnter
  79. {
  80. if (self.delegate != nil && [self.delegate respondsToSelector:@selector(clickEnter)]) {
  81. [XTGuidePagesViewController saveCurrentVersion];
  82. [self.delegate clickEnter];
  83. }
  84. }
  85. + (BOOL)isShow
  86. {
  87. // 读取版本信息
  88. NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
  89. NSString *localVersion = [user objectForKey:VERSION_INFO_CURRENT];
  90. NSString *currentVersion =[[NSBundle mainBundle].infoDictionary objectForKey:@"CFBundleShortVersionString"];
  91. if (localVersion == nil || ![currentVersion isEqualToString:localVersion]) {
  92. return YES;
  93. }else
  94. {
  95. return NO;
  96. }
  97. }
  98. // 保存版本信息
  99. + (void)saveCurrentVersion
  100. {
  101. NSString *version =[[NSBundle mainBundle].infoDictionary objectForKey:@"CFBundleShortVersionString"];
  102. NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
  103. [user setObject:version forKey:VERSION_INFO_CURRENT];
  104. [user synchronize];
  105. }
  106. #pragma mark - ScrollerView Delegate
  107. - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
  108. {
  109. self.pageControl.currentPage = scrollView.contentOffset.x / s_w;
  110. }
  111. @end