新浪微部落格戶端(11)-自定義checkBox

weixin_30788239發表於2020-04-05

 

在最後一個歡迎介面上新增一個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");

}

 

最終效果:

 

轉載於:https://www.cnblogs.com/yongdaimi/p/5994394.html

相關文章