ios 实现引导页面效果

//

//  ViewController.m

//  UIScrollView-分页

//

//  Created by  朱立志 on 14-5-1.

//  Copyright (c) 2014  朱立志. All rights reserved.

//

#define count 5

#import "ViewController.h"



@interface ViewController ()

{

    UIPageControl *_control;

    UIScrollView *scrollView;

}




@end


@implementation ViewController


- (void)viewDidLoad

{

    [super viewDidLoad];

UIScrollView *uiScrollview = [[UIScrollView alloc] init];

    uiScrollview.frame = self.view.bounds;

    CGFloat width = self.view.frame.size.width;

    CGFloat height = self.view.frame.size.height;

    

    [self.view addSubview:uiScrollview];

    

    for (int i = 0; i < count; i++) {

        NSString *imageName = [NSString  stringWithFormat:@"pages.bundle/%d.jpg" ,i+1];

        UIImage *image = [UIImage imageNamed: imageName];

        UIImageView *imageView = [[UIImageView alloc] initWithImage:image];

        imageView.frame = CGRectMake(i*width, 0, width, height);

        [uiScrollview addSubview:imageView];

    }

    scrollView = uiScrollview;

    uiScrollview.showsHorizontalScrollIndicator = NO;

    uiScrollview.contentSize = CGSizeMake(count*width, height);

    uiScrollview.pagingEnabled = YES;

    uiScrollview.backgroundColor = [UIColor grayColor];

    uiScrollview.delegate = self;

    

    UIPageControl *control = [[UIPageControl alloc] init];

    control.numberOfPages = count;

    control.bounds = CGRectMake(0, 0, 200, 50);

    control.center = CGPointMake(width*0.5, height-50);

    control.currentPage = 0;

    _control = control;

    [_control addTarget:self action:@selector(onPointClick) forControlEvents:UIControlEventValueChanged];

    [self.view addSubview:control];

    

    

}


- (void) onPointClick

{

    NSLog(@"onPointClick");

    CGFloat offsetX = _control.currentPage * scrollView.frame.size.width;

    [UIView animateWithDuration:0.3 animations:^{

        scrollView.contentOffset = CGPointMake(offsetX, 0);

    }];

    

}


- (void)didReceiveMemoryWarning

{

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView

{

    

    int pageNum = scrollView.contentOffset.x / scrollView.frame.size.width;

    _control.currentPage = pageNum;

}


@end

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值