agiapp / BRPickerView

BRPickerView 封装的是iOS中常用的选择器组件,主要包括:日期选择器(支持年月日、年月等15种日期样式选择,支持设置星期、至今等)、地址选择器(支持省市区、省市、省三种地区选择)、自定义字符串选择器(支持单列、多列、二级联动、三级联动选择)。支持自定义主题样式,适配深色模式,支持将选择器组件添加到指定容器视图。
https://github.com/agiapp/BRPickerView
MIT License
2.57k stars 446 forks source link

使用[stringPickerView addPickerToView:centerView];方法不可以添加到指定View上 #144

Closed TomWang1 closed 4 years ago

TomWang1 commented 4 years ago

` //添加picker UIView centerView = [[UIView alloc] init]; centerView.autoresizingMask = UIViewAutoresizingFlexibleWidth; [backView addSubview:centerView]; [centerView mas_makeConstraints:^(MASConstraintMaker make) { make.left.right.mas_equalTo(0); make.top.mas_equalTo(titleLabel.mas_bottom).offset(9); make.bottom.mas_equalTo(makeSureBtn.mas_top).offset(-15); }]; [self layoutIfNeeded]; BRStringPickerView stringPickerView = [[BRStringPickerView alloc]init]; // stringPickerView.pickerMode = BRStringPickerComponentMulti; stringPickerView.title = @"自定义多列字符串"; stringPickerView.dataSourceArr = @[@[@"竞拍时间"], @[ @"1", @"2", @"3", @"4", @"5", @"6", @"7", @"8", @"9", @"10", @"11", @"12", @"13", @"14", @"15", @"16", @"17", @"18", @"19", @"20", @"21", @"22", @"23", @"24", @"25", @"26", @"27", @"28", @"29", @"30", @"31", @"32", @"33", @"34", @"35", @"36", @"37", @"38", @"39", @"40", @"41", @"42", @"43", @"44", @"45", @"46", @"47", @"48", @"49", @"50", @"51", @"52", @"53", @"54", @"55", @"56", @"57", @"58", @"59"],@[@"分"]]; // stringPickerView.selectIndexs = self.otherSelectIndexs; //stringPickerView.selectValues = [self.infoModel.otherStr componentsSeparatedByString:@","]; stringPickerView.isAutoSelect = YES; stringPickerView.resultModelArrayBlock = ^(NSArray<BRResultModel > *resultModelArr) {

           };

           // 设置选择器中间选中行的样式
           BRPickerStyle *customStyle = [[BRPickerStyle alloc]init];

// customStyle.selectRowTextFont = [UIFont boldSystemFontOfSize:23.0f]; // customStyle.selectRowTextColor = [UIColor br_labelColor]; stringPickerView.pickerStyle = customStyle; // [stringPickerView show]; [stringPickerView addPickerToView:centerView]; `

agiapp commented 4 years ago

centerView要设置frame,stringPickerView会自动填满centerView视图------------------ 原始邮件 ------------------ 发件人: "TomWang1"notifications@github.com 发送时间: 2020年5月4日(星期一) 下午3:18 收件人: "91renb/BRPickerView"BRPickerView@noreply.github.com; 抄送: "Subscribed"subscribed@noreply.github.com; 主题: [91renb/BRPickerView] 使用[stringPickerView addPickerToView:centerView];方法不可以添加到指定View上 (#144)

//添加picker UIView *centerView = [[UIView alloc] init]; centerView.autoresizingMask = UIViewAutoresizingFlexibleWidth; [backView addSubview:centerView];

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.

TomWang1 commented 4 years ago

设置了 Frame还是不可以。使用masonry设置布局不可以吗?我在调用addPickerToView的时候,可以看到Frame。centerView.frame = CGRectMake(0, 49.5, kScreenWidth - 24, 157);

agiapp commented 4 years ago

可以使用masonry设置布局,您数据源传的是二维数组,所以必须要设置stringPickerView.pickerMode = BRStringPickerComponentMulti; 可以参考下面代码:

UIView *centerView = [[UIView alloc]init];
[_footerView addSubview:centerView];
[centerView mas_makeConstraints:^(MASConstraintMaker *make) {
    make.left.mas_equalTo(30);
    make.right.mas_equalTo(-30);
    make.top.mas_equalTo(170);
    make.height.mas_equalTo(200);
}];
BRStringPickerView *stringPickerView = [[BRStringPickerView alloc]init];
stringPickerView.pickerMode = BRStringPickerComponentMulti;
stringPickerView.title = @"自定义多列字符串";
stringPickerView.dataSourceArr = @[@[@"竞拍时间"], @[@"1", @"2", @"3", @"4", @"5", @"6", @"7", @"8", @"9", @"10", @"11", @"12", @"13", @"14", @"15", @"16", @"17", @"18", @"19", @"20", @"21", @"22", @"23", @"24", @"25", @"26", @"27", @"28", @"29", @"30", @"31", @"32", @"33", @"34", @"35", @"36", @"37", @"38", @"39", @"40", @"41", @"42", @"43", @"44", @"45", @"46", @"47", @"48", @"49", @"50", @"51", @"52", @"53", @"54", @"55", @"56", @"57", @"58", @"59"], @[@"分"]];
stringPickerView.isAutoSelect = YES;
stringPickerView.resultModelArrayBlock = ^(NSArray<BRResultModel *> *resultModelArr) {

};
[stringPickerView addPickerToView:centerView];