ios-新浪微博开发-14(新特性2)

88 篇文章 0 订阅

在上次的基础上进行代码的修改

#import "QHNewfeatureViewController.h"

#define QHNewfeatureCount 4

@interface QHNewfeatureViewController ()<UIScrollViewDelegate>

@property(nonatomic,weak)UIPageControl *pageControl;
@end

@implementation QHNewfeatureViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    
    
    //1.创建一个scrollView
    UIScrollView *scrollView = [[UIScrollView alloc]init];
    
    scrollView.frame = self.view.bounds;
    scrollView.delegate = self;
    [self.view addSubview:scrollView];
    
    CGFloat scrollW = scrollView.width;
    CGFloat scrollH = scrollView.height;
    //2.添加图片到scrollView
    for (int i = 0; i < QHNewfeatureCount; i++) {
        UIImageView *imageView = [[UIImageView alloc]init];
        imageView.width = scrollW;
        imageView.height = scrollH;
        imageView.y = 0;
        imageView.x = i *imageView.width;
        //显示图片
        NSString *name = [NSString stringWithFormat:@"new_feature_%d",i+1];
        imageView.image = [UIImage imageNamed:name];
        [scrollView addSubview:imageView];
        
        //如果是最后一个imageView 就往里面添加内容
        if(i == QHNewfeatureCount - 1)
        {
            [self setupLastImageView:imageView];
        }
    }
    
#warning 默认情况下 scrollView 一创建出来 它里面就可能存在一些控件了 
#warning  就算不主动添加一些控件到scrollView中 内部还还是可能会有一些控件
    
    
    
    
    //3.设置scrollView的其他属性
    //如果想要某个方向不能滚动 那么那个方向对应的储存数值传0
    scrollView.contentSize = CGSizeMake(QHNewfeatureCount *scrollView.width, 0);
    
    //取出弹簧效果
    scrollView.bounces = NO;
    scrollView.pagingEnabled = YES;
    scrollView.showsHorizontalScrollIndicator = NO;
    
    //4.设置pageControll
    UIPageControl *pageControl = [[UIPageControl alloc]init];
    pageControl.numberOfPages = QHNewfeatureCount;

    //@property(nonatomic,retain) UIColor *pageIndicatorTintColor NS_AVAILABLE_IOS(6_0) UI_APPEARANCE_SELECTOR;
    //@property(nonatomic,retain) UIColor *currentPageIndicatorTintColor
    pageControl.currentPageIndicatorTintColor =[UIColor colorWithRed:0.98f green:0.38f blue:0.11f alpha:1.00f];
    pageControl.pageIndicatorTintColor =[UIColor colorWithRed:0.74f green:0.74f blue:0.74f alpha:1.00f];

    
    pageControl.centerX = scrollView.width *0.5;
    pageControl.centerY = scrollView.height - 50;
    [self.view addSubview:pageControl];
    
    self.pageControl = pageControl;
//    不用设置尺寸也可以显示
//    pageControl.width = 100;
//    pageControl.height = 50;
//    pageControl.userInteractionEnabled = NO;
    
    /**
     *[UIColor colorWithRed:0.98f green:0.38f blue:0.11f alpha:1.00f];橙色
     *[UIColor colorWithRed:0.74f green:0.74f blue:0.74f alpha:1.00f];灰色
     */
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
//    int page = scrollView.contentOffset.x/scrollView.width;
//    self.pageControl.currentPage = page;
//    QHLog(@"%ld",(long)self.pageControl.currentPage);
    double page = scrollView.contentOffset.x/scrollView.width;
    self.pageControl.currentPage = (int)(page + 0.5);
}


- (void)setupLastImageView:(UIImageView *)imageView
{
    //开启用户交互
    imageView.userInteractionEnabled = YES;
    
    //1.分享给大家(check box)
    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:15];
    shareBtn.width = 100;
    shareBtn.height = 30;
    shareBtn.centerX = imageView.width *0.5;
    shareBtn.centerY = imageView.height *0.6;
    
    
    [shareBtn addTarget:self action:@selector(shareClick:) forControlEvents:UIControlEventTouchUpInside];
    [imageView addSubview:shareBtn];
    
    //EdgeInsets:自切 背景色是一种很好的调试工具
    //top left bottom right  会影响按钮里面的所有内容(里面的imageView 和 titleLabel)
//    shareBtn.contentEdgeInsets = UIEdgeInsetsMake(<#CGFloat top#>, <#CGFloat left#>, <#CGFloat bottom#>, <#CGFloat right#>);

    //这个只影响titlelabel 的属性
    //    shareBtn.titleEdgeInsets = UIEdgeInsetsMake(<#CGFloat top#>, <#CGFloat left#>, <#CGFloat bottom#>, <#CGFloat right#>)
    shareBtn.imageEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 0 );
//    shareBtn.titleEdgeInsets 内边距
//    shareBtn.imageEdgeInsets
//    shareBtn.contentEdgeInsets
    
    //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:UIControlStateSelected];
    
    startBtn.size = startBtn.currentBackgroundImage.size;
    startBtn.centerX = shareBtn.centerX;
    startBtn.centerY = imageView.height *0.75;
    [startBtn setTitle:@"开始微博" forState:UIControlStateNormal];
    [imageView addSubview:startBtn];
    
}

- (void)shareClick:(UIButton *)shareBtn
{
    //状态取反
    shareBtn.selected = !shareBtn.selected;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值