新浪微博客户端(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");

}
复制代码

 

最终效果:

 



如果您觉得阅读本文对您有帮助,请点一下“推荐”按钮,您的“推荐”将是我最大的写作动力!欢迎各位转载,但是未经作者本人同意,转载文章之后必须在文章页面明显位置给出作者和原文连接,否则保留追究法律责任的权利。
posted @   夜行过客  阅读(211)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
阅读排行:
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
点击右上角即可分享
微信分享提示