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

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值