新浪微博客户端(11)-自定义checkBox

 

在最后一个欢迎界面上添加一个CheckBox.

// 2.添加4个UIImageView
    for (int i = 0; i < NEW_FEATURE_NUMS; i++) {
       UIImageView *imageView = [[UIImageView alloc] init];
        imageView.size = scrollView.size;
        imageView.y = 0;
        imageView.x = i * scrollW;
        NSString *imageName = [NSString stringWithFormat:@"new_feature_%d",i+1];
        imageView.image = [UIImage imageNamed:imageName];
        [scrollView addSubview:imageView];
        
        // 如果是最后一张图片,则添加进入按钮
        if (i == NEW_FEATURE_NUMS - 1) {
            [self setupEnterBtn:imageView];
        }
        
    }

 

/** 添加分享checkbox及进入微博按钮 */
- (void)setupEnterBtn:(UIImageView *)imageView {

    // 0.设置imageView可以交互
    imageView.userInteractionEnabled = YES;
    
    // 1.添加shareBtn
    UIButton *shareBtn = [[UIButton alloc] init];
    [shareBtn setImage:[UIImage imageNamed:@"checkbox_unchecked"] forState:UIControlStateNormal];
    [shareBtn setImage:[UIImage imageNamed:@"checkbox_checked"] forState:UIControlStateSelected];
    
    [shareBtn setTitle:@"分享到微博" forState:UIControlStateNormal];
    [shareBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    shareBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    shareBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 16, 0, 0);
    shareBtn.width = 200;
    shareBtn.height = 44;
    shareBtn.centerX = imageView.width * 0.5;
    shareBtn.centerY = imageView.height * 0.75;
    [shareBtn addTarget:self action:@selector(shareBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    
    [imageView addSubview:shareBtn];
    
    
    // 2.添加进入微博按钮
    UIButton *enterBtn = [[UIButton alloc] init];
    [enterBtn setBackgroundImage:[UIImage imageNamed:@"new_feature_button"] forState:UIControlStateNormal];
    [enterBtn setBackgroundImage:[UIImage imageNamed:@"new_feature_button_highlighted"] forState:UIControlStateHighlighted];
    enterBtn.size = enterBtn.currentBackgroundImage.size;
    enterBtn.centerX = shareBtn.centerX;
    enterBtn.centerY = imageView.height * 0.82;
    [imageView addSubview:enterBtn];
    
}



- (void)shareBtnClick:(UIButton *)btn {

    btn.selected = !btn.isSelected;
    
    DJLog(@"fdfd");

}

 

最终效果:

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值