WelcomeVC.m 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. //
  2. // WelcomeVC.m
  3. // LNManager
  4. //
  5. // Created by EchoShacolee on 2018/1/12.
  6. // Copyright © 2018年 lee. All rights reserved.
  7. //
  8. #import "WelcomeVC.h"
  9. #import "LoginViewController.h"
  10. @interface WelcomeVC ()<UIScrollViewDelegate>
  11. {
  12. UIPageControl *pageControl;
  13. }
  14. @end
  15. @implementation WelcomeVC
  16. - (void)viewDidLoad {
  17. [super viewDidLoad];
  18. [self myInit];
  19. }
  20. -(void)myInit
  21. {
  22. NSArray* images = @[@"下载欢迎页1.png",@"下载欢迎页2.png",@"下载欢迎页3.png"];
  23. UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, kSize.width, kSize.height)];
  24. /**跳到第5页,也会欢迎结束
  25. */
  26. [scroll setContentSize:CGSizeMake(kSize.width* images.count+1, 0)];
  27. [scroll setBounces:NO];
  28. [scroll setShowsHorizontalScrollIndicator:NO];
  29. scroll.delegate = self;
  30. scroll.pagingEnabled = YES;
  31. [self.view addSubview:scroll];
  32. pageControl = [[UIPageControl alloc]initWithFrame:CGRectMake(0, kSize.height-50, kSize.width, 20)];
  33. pageControl.numberOfPages = scroll.contentSize.width/scroll.frame.size.width;
  34. [self.view addSubview:pageControl];
  35. UIImageView* iv;
  36. for (int i =0; i<images.count; i++) {
  37. iv = [[UIImageView alloc] initWithFrame:kFrame];
  38. iv.x = kSize.width*i;
  39. [scroll addSubview:iv];
  40. [iv setImage:[UIImage imageNamed:images[i]]];
  41. if (i==images.count-1) {
  42. UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
  43. btn.frame = CGRectMake(kSize.width/2-45, kSize.height-90, 100, 40);
  44. btn.layer.masksToBounds = YES;
  45. btn.layer.cornerRadius = 8;
  46. btn.layer.borderWidth = 1;
  47. btn.layer.borderColor = [UIColor whiteColor].CGColor;
  48. [btn setTitle:@"请登录" forState:UIControlStateNormal];
  49. [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  50. btn.backgroundColor = [UIColor clearColor];
  51. [btn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];
  52. [iv addSubview:btn];
  53. iv.userInteractionEnabled = YES;
  54. }
  55. }
  56. }
  57. -(void)btnClick{
  58. LoginViewController * loginvc = [[LoginViewController alloc]init];
  59. [UIApplication sharedApplication].keyWindow.rootViewController = loginvc;
  60. }
  61. - (void)scrollViewDidScroll:(UIScrollView *)scrollView{
  62. CGPoint off = scrollView.contentOffset;
  63. if (off.x / kSize.width > 2) {
  64. LoginViewController * loginvc = [[LoginViewController alloc]init];
  65. [UIApplication sharedApplication].keyWindow.rootViewController = loginvc;
  66. }
  67. }
  68. - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
  69. pageControl.currentPage = scrollView.contentOffset.x/scrollView.frame.size.width;
  70. }
  71. - (void)didReceiveMemoryWarning {
  72. [super didReceiveMemoryWarning];
  73. // Dispose of any resources that can be recreated.
  74. }
  75. /*
  76. #pragma mark - Navigation
  77. // In a storyboard-based application, you will often want to do a little preparation before navigation
  78. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  79. // Get the new view controller using [segue destinationViewController].
  80. // Pass the selected object to the new view controller.
  81. }
  82. */
  83. @end