iOS小技能:控件右上角添加文字/icon

214 阅读2分钟

「这是我参与2022首次更文挑战的第24天,活动详情查看:2022首次更文挑战」。

引言

应用场景:

  1. 因银行代发通道收费每笔1元,为减少代理商提现成本,支持各分佣的合并提现。
  2. 多张证明材料图片上传

I 控件右上角添加文字(Frame布局)

因银行代发通道收费每笔1元,为减少代理商提现成本,支持各分佣的合并提现。

在这里插入图片描述

        UIButton *titBtn = [ControlManager getButtonWithFrame:CGRectMake(scrollView.width - KWratio(70), lefterTitleLab.y, KWratio(50), KWratio(55)) fontSize:displayFontSize(13.0f) title:@"提现 >" titleColor:HWColor(87, 146, 204) image:[UIImage new] backgroundColor:[UIColor clearColor] cornerRadius:0];
        
        if(dto.is_merge_drawal){//99
            UILabel*   _badgeLab = [ControlManager text:@"推荐" font:displayFontSize(9.0f) color:[UIColor whiteColor] alingment:1 fontWithName:@"PingFang-SC-Medium"];
            _badgeLab.textAlignment = NSTextAlignmentCenter;
                   
                   _badgeLab.backgroundColor = BASE_RED_COLOR;
               
                   _badgeLab.layer.masksToBounds = YES;
               
                   [titBtn addSubview:_badgeLab];
               
               
               
            CGSize titleSizes = [_badgeLab.text sizeWithFont:[UIFont systemFontOfSize:displayFontSize(9.0f)] constrainedToSize:CGSizeMake(kWidth, 13)];//200
            
            

            _badgeLab.frame = CGRectMake(titBtn.width - titleSizes.width / 2, 7, titleSizes.width + KWratio(4) , KWratio(13));
            _badgeLab.layer.cornerRadius = KWratio(5);




        }
        

II 控件右上角添加icon(Masonry布局)

在这里插入图片描述


#define KNDeleteH 7 //删除按钮的高度的一半

@property (nonatomic,weak) UIImageView *imageView;

@property (nonatomic,weak) UIButton *deleteBtn;


- (UIImageView *)imageView{
    if (nil == _imageView) {
        UIImageView *tmpView = [[UIImageView alloc]init];
        _imageView = tmpView;
        tmpView.contentMode = UIViewContentModeScaleAspectFill;
        tmpView.clipsToBounds = YES;
        [self addSubview:_imageView];
        
        __weak __typeof__(self) weakSelf = self;

        [tmpView mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.top.offset(kAdjustRatio(KNDeleteH));
            make.left.offset(kAdjustRatio(KNDeleteH));
            make.right.offset(kAdjustRatio(-KNDeleteH));
            
            
            make.bottom.offset(kAdjustRatio(-KNDeleteH));

            

        }];
        
        tmpView.userInteractionEnabled = YES;
        
        UITapGestureRecognizer *cutTap = [[UITapGestureRecognizer alloc] init];
//        __weak __typeof__(self) weakSelf = self;
        
        [[cutTap rac_gestureSignal] subscribeNext:^(id x) {
            
            
            
            
            if(weakSelf.model.type != QCTCollectionModelType4UploadPicturesAddIcon
               ){
                
                return ;
                
                
                
            }
            
            NSLog(@" 上传图片 ");
            
            
            if (weakSelf.model.block) {
                
                weakSelf.model.block(weakSelf.model);
                
                
            }
            
        }];
        [tmpView addGestureRecognizer:cutTap];
        
    }
    return _imageView;
}

- (UIButton *)deleteBtn{
    if (nil == _deleteBtn) {
        UIButton *tmpView = [[UIButton alloc]init];
        _deleteBtn = tmpView;
        [tmpView addTarget:self action:@selector(clickDeleteBtn) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_deleteBtn];
//
        __weak __typeof__(self) weakSelf = self;

        [tmpView mas_makeConstraints:^(MASConstraintMaker *make) {
           
            make.centerY.equalTo(weakSelf.imageView.mas_top);
            make.centerX.equalTo(weakSelf.imageView.mas_right);
            

                    
            make.width.height.mas_equalTo(kAdjustRatio(2*KNDeleteH));
            
            
            
            
        }];
    }
    return _deleteBtn;
}

see also

1、请输入正确的结算卡号【银行卡号有效性校验Luhn算法】-银行卡号码校验算法2、身份证校验:【校验年龄、校验是否符合身份证号生成规则】

blog.csdn.net/z929118967/…

OC中的 BOOL不如bool好用

BOOL表示 1是YES , 所以非1是NO. 而bool表示0是false,所以非0是true;

🍅 联系作者: iOS逆向(公号:iosrev)


🍅 作者简介:CSDN 博客专家认证🏆丨全站 Top 50、华为云云享专家认证🏆、iOS逆向公号号主


🍅 简历模板、技术互助。关注我,都给你。