Github+Jekyll搭建个人博文网站

在很多的app应用开发中,当第一次启动应用的时候都会来一个引导页,其效果如下图所示。
这里写图片描述

此处,我们使用UIScrollView来实现一个这样的效果,涉及的代码有。
WelcomeViewController.h

#import <UIKit/UIKit.h> 

@interface WelcomeViewController : UIViewController 

@end 

逻辑处理WelcomeViewController.m

#import "WelcomeViewController.h" 
#define IMAGECOUNT 3 

@interface WelcomeViewController () <UIScrollViewDelegate> 
@property (nonatomic, strong)UIPageControl *pageControl; 

@end 

@implementation WelcomeViewController 

- (void)viewDidLoad { 
  [super viewDidLoad]; 
  //创建ScrollView 
  UIScrollView *sv = [[UIScrollView alloc] init]; 
  sv.frame = self.view.bounds; 
  //设置边缘不弹跳 
  sv.bounces = NO; 
  //整页滚动 
  sv.pagingEnabled = YES; 
  sv.showsHorizontalScrollIndicator = NO; 

  //加入多个子视图(ImageView) 
  for(NSInteger i=0; i<IMAGECOUNT; i++){ 
    NSString *imgName = [NSString stringWithFormat:@"%ld", i+1]; 
    UIImage *image = [UIImage imageNamed:imgName]; 
    UIImageView *imageView = [[UIImageView alloc]initWithImage:image]; 
    CGRect frame = CGRectZero; 
    frame.origin.x = i * sv.frame.size.width; 
    frame.size = sv.frame.size; 
    imageView.frame = frame; 
    [sv addSubview:imageView]; 

    if(i==IMAGECOUNT-1){ 
      //开启图片的用户点击功能 
      imageView.userInteractionEnabled = YES; 
      //加个按钮 
      UIButton *button = [[UIButton alloc]init]; 

      button.frame = CGRectMake((imageView.frame.size.width-150)/2, imageView.frame.size.height*0.8, 150, 40); 
      button.backgroundColor = [UIColor orangeColor]; 
      [button setTitle:@"立即体验" forState:UIControlStateNormal]; 
      button.titleLabel.font = [UIFont boldSystemFontOfSize:16]; 
      [imageView addSubview:button]; 
      [button addTarget:self action:@selector(enter) forControlEvents:UIControlEventTouchUpInside];    } 
  } 

  sv.contentSize = CGSizeMake(IMAGECOUNT * sv.frame.size.width, sv.frame.size.height); 

  [self.view addSubview:sv]; 

  //加入页面指示控件PageControl 
  UIPageControl *pageControl = [[UIPageControl alloc]init]; 
  self.pageControl = pageControl; 
  //设置frame 
  pageControl.frame = CGRectMake(0, self.view.frame.size.height - 40, self.view.frame.size.width, 20); 
  //分页面的数量 
  pageControl.numberOfPages = IMAGECOUNT; 
  //设置小圆点渲染颜色 
  pageControl.pageIndicatorTintColor = [UIColor whiteColor]; 
  //设置当前选中小圆点的渲染颜色 
  pageControl.currentPageIndicatorTintColor = [UIColor redColor]; 
  //关闭用户点击交互 
  pageControl.userInteractionEnabled = NO; 

  [self.view addSubview:pageControl]; 

  sv.delegate = self; 


} 
- (void)enter 
{ 
  NSLog(@"进入应用"); 
} 

//UIScrollViewDelegate方法 
- (void)scrollViewDidScroll:(UIScrollView *)scrollView 
{ 
  CGPoint offset = scrollView.contentOffset; 
  if(offset.x<=0){ 
    offset.x = 0; 
    scrollView.contentOffset = offset; 
  } 
  NSUInteger index = round(offset.x / scrollView.frame.size.width); 
  self.pageControl.currentPage = index; 
} 

- (void)didReceiveMemoryWarning { 
  [super didReceiveMemoryWarning]; 
  // Dispose of any resources that can be recreated. 
} 

@end

到此,一个简单的引导页面就完成了。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

xiangzhihong8

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值