IOS学习之——欢迎界面

//
//  MyViewController.m
//

#import "MyViewController.h"

@interface MyViewController () <UIScrollViewDelegate>

@property(nonatomic,strong)UIScrollView *sv;
@property(nonatomic,strong)UIPageControl *pc;
@end

@implementation MyViewController

//scrollView的代理方法  已经滑动时调用
-(void)scrollViewDidScroll:(UIScrollView *)scrollView {
//    round  返回的是参数中浮点数 四舍五入后 的值
    //当前在 第几页上
    int currentPageNum = round(scrollView.contentOffset.x / scrollView.frame.size.width);
    self.pc.currentPage = currentPageNum;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    //设置 scrollView相关内容
    [self configScrllView];
    [self configPageControl];
}

//设置下面的4个原点
-(void)configPageControl {
    self.pc = [[UIPageControl alloc]init];
    self.pc.frame = CGRectMake(0, self.view.frame.size.height - 60, self.view.frame.size.width, 40);
    //有几个点
    self.pc.numberOfPages = 4;
    //当前 选中的时第几个点  默认不设置是0
    self.pc.currentPage = 0;
    //每个点的颜色是什么
    self.pc.pageIndicatorTintColor = [UIColor redColor];
    //当前 选中的 点 颜色是什么
    self.pc.currentPageIndicatorTintColor = [UIColor greenColor];
    //关闭用户交互
    self.pc.userInteractionEnabled = NO;
    
    [self.view addSubview:self.pc];
}

-(void)configScrllView {
    //设置 scrollView 的 可见区域和屏幕一样大
    self.sv = [[UIScrollView alloc]initWithFrame:self.view.frame];
    self.sv.delegate = self;
    //设置内容区域
    self.sv.contentSize = CGSizeMake(4 * self.view.frame.size.width, self.view.frame.size.height);
    //向scrollView中添加内容
    for (int i = 0; i < 4; i++) {
        NSString *imageName = [NSString stringWithFormat:@"welcome%d", i + 1];
        UIImageView *iv = [[UIImageView alloc]initWithImage:[UIImage imageNamed:imageName]];
        iv.frame = CGRectMake(i * self.view.frame.size.width, 0, self.view.frame.size.width, self.view.frame.size.height);
        [self.sv addSubview:iv];
    }
    //设置整页滑动
    self.sv.pagingEnabled = YES;
    //关闭scrollView 的 弹跳
    self.sv.bounces = NO;
    //关闭水平的滑动条
    self.sv.showsHorizontalScrollIndicator = NO;
    
    [self.view addSubview:self.sv];
}



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

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end

你可能感兴趣的:(IOS学习之——欢迎界面)