【项目实战】项目新特性页面总结

每个App新版的时候,总有一些变化,主流上基本会将一个新版本的新特性,以图片轮播的形式展示新特性的图片

为新特性新建一个继承UIViewController的控制器管理新特性的逻辑

 

 

->创建一个控制器的view来管理软件新特性

-> 创建一个ScrollView

// 1.创建一个ScrollView : 显示所有的新特性图片
    UIScrollView *scrollView = [[UIScrollView alloc] init];
    scrollView.frame = self.view.bounds; // 设置frame为窗口大小
    [self.view addSubview:scrollView];

 

-> 设置ScrollView里面的imageView属性

// 2 .设置ScrollView里面的ImageView属性
    CGFloat scrollW = scrollView.width;
    CGFloat scrollH = scrollView.height;
    // 加载图片
    for (int i = 0; i < HWNewFeatureCount; i ++) {
        UIImageView *imageView = [[UIImageView alloc] init];

        imageView.height = scrollH;
        imageView.width = scrollW;
        imageView.y = 0;
        imageView.x = i * scrollW; 
        
        NSString *imageName = [NSString stringWithFormat:@"newFeature%d",i + 1];
        imageView.image = [UIImage imageNamed:imageName];
        [scrollView addSubview:imageView];
        
        // 如果是最后一个imageView. 就往里面添加其他内容
        if(i == HWNewFeatureCount - 1){
            [self setupLastImageView:imageView];
        }
        
        
    }

 

->[self setupLastImageView:imageView] 最后一个图片的设置

// 开启交互功能
    imageView.userInteractionEnabled = YES;
    
    // 1. 分享给大家 选中框按钮
    UIButton *shareBtn = [[UIButton alloc] init];
    [shareBtn setImage:[UIImage imageNamed:@"new_feature_share_false"] forState:UIControlStateNormal];
    [shareBtn setImage:[UIImage imageNamed:@"new_feature_share_true"] forState:UIControlStateSelected];
    [shareBtn setTitle:@"分享给大家" forState:UIControlStateNormal];
    [shareBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    shareBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    shareBtn.width = 150;
    shareBtn.height = 30;
    shareBtn.centerX = imageView.width * 0.5;
    shareBtn.centerY = imageView.height * 0.65;
    [shareBtn addTarget:self action:@selector(shareClick:) forControlEvents:UIControlEventTouchUpInside];
    [imageView addSubview:shareBtn];
    
    
    // 关于 EdgeInsets属性的一些总结
    // ------------------
    // EdgeInsets: 自切(理解为自己切掉自己的一些内容区域即可)
    // contentEdgeInsets:会影响按钮内部的所有内容(里面的imageView和titleLabel)
    // titleEdgeInsets:只影响按钮内部的titleLabel  只切内部的titleLabel
    // imageEdgeInsets:只影响按钮内部的imageView   只切内部的imageView
    
    // ------------------
    shareBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
    
    // 2.分享微博按钮
    UIButton *startBtn = [[UIButton alloc] init];
    [startBtn setBackgroundImage:[UIImage imageNamed:@"new_feature_finish_button"] forState:UIControlStateNormal];
    [startBtn setBackgroundImage:[UIImage imageNamed:@"new_feature_finish_button_highlighted"] forState:UIControlStateHighlighted];
    [startBtn setTitle:@"开启旅程" forState:UIControlStateNormal];
    [startBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    startBtn.titleLabel.font = [UIFont systemFontOfSize:15];
    startBtn.size = startBtn.currentBackgroundImage.size;
    startBtn.centerX = shareBtn.centerX;
    startBtn.centerY = imageView.height * 0.72;
    [startBtn addTarget:self action:@selector(startClick:) forControlEvents:UIControlEventTouchUpInside];
    
    
    [imageView addSubview:startBtn];

 

 

 

 

-> 设置ScrollView的属性,使之符合页面属性

// 3. 设置ScrollView的其他属性
    // 想要某个方向上步能滚动,那么这个方向对应的尺寸数值传0即可
    scrollView.contentSize = CGSizeMake(scrollView.width * HWNewFeatureCount, 0); //
    
    scrollView.bounces = NO ;// 去除弹簧效果
    scrollView.pagingEnabled = YES; // 添加分页效果
    scrollView.showsHorizontalScrollIndicator = NO; // 去除滚动条
    scrollView.delegate = self; // 设置代理

 

-> 添加分页圆点,pageControl

// 4. 添加pageControl : 分页, 展示目前看得是第几页
    // UIPageControl就算没有设置尺寸,里面的内容还是照常显示的
    UIPageControl *pageControl = [[UIPageControl alloc] init];
    pageControl.numberOfPages = HWNewFeatureCount; // 设置圆点数量
    pageControl.width = 100;
//    pageControl.height = 50; // 不设置pageControl的高度,是因为不需要给它点击,等于设置了userInterractionEnabled
    pageControl.centerX = scrollW * 0.5;
    pageControl.centerY = scrollH - 50;
    
    pageControl.currentPageIndicatorTintColor = HWColor(253, 98, 42);
    pageControl.pageIndicatorTintColor = HWColor(198, 198,198);
    self.pageControl = pageControl; // 需要定义属性,将变量传入属性,方便下面代理方法监听使用
    [self.view addSubview:pageControl];

 

-> scrollView代理方法(监听滚动范围,控制pageControl)

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    double page = scrollView.contentOffset.x / scrollView.width;
    // 四舍五入计算出页码
    self.pageControl.currentPage = (int)(page + 0.5);
    // 1.3四舍五入 1.3 + 0.5 = 1.8 强转为整数(int)1.8= 1
}

 

posted @ 2015-11-03 10:11  Travin-C  阅读(158)  评论(0编辑  收藏  举报