循环 创建 UIButton 并添加选中状态 (单选和多选)

这篇博客介绍了如何在iOS开发中自定义一个View,用于循环创建UIButton,并实现单选和多选的选中状态管理。作者Guide_Sun详细阐述了实现过程,包括按钮的创建、选中状态的维护等关键步骤。
摘要由CSDN通过智能技术生成

自己封装一个View

/在.h声明
@interface SelectView : UIView
@property(nonatomic,assign)NSInteger selectIndex;
- (instancetype)initWithTitle:(NSString *)title andItemArrar:(NSArray *)items;
@end
//在.m里面实现
#import "SelectView.h"
#import "Masonry.h"
@interface SelectView()
@property(nonatomic,strong)UILabel * titleLabel;
@property(nonatomic,strong)UIButton * selectBtn;
@property(nonatomic,strong)NSString * title;
@property(nonatomic,strong)NSArray * items;

@end
@implementation SelectView
- (instancetype)initWithTitle:(NSString *)title andItemArrar:(NSArray *)items{
    if (! (self = [super init]))
        return nil;
    self.backgroundColor = [UIColor yellowColor];
    _title = title;
    _items = items;
    [self addSubview:self.titleLabel];
    [self layoutPageFrame];
    [self addSubview:self.selectBtn];
    return self;
}
//点击事件
- (void)selectBtnClick:(UIButton *)s
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值