From 6af175d6910f3ce4d373eefafc518ca25e339c2f Mon Sep 17 00:00:00 2001 From: xwenliang Date: Fri, 18 May 2018 19:37:00 +0800 Subject: [PATCH] new feature pickerFontFamily for both android and ios --- README.md | 2 +- index.d.ts | 2 +- ios/RCTBEEPickerManager/BzwPicker.h | 3 +- ios/RCTBEEPickerManager/BzwPicker.m | 41 +++++++------------ ios/RCTBEEPickerManager/RCTBEEPickerManager.m | 5 ++- package.json | 2 +- 6 files changed, 23 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index 4030ecf..82ac41e 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ |wheelFlex | array | [1, 1, 1] | iOS/Android | | |pickerFontSize | number | 16 | iOS/Android | | |pickerFontColor | array | [31, 31, 31, 1] | iOS/Android | | -|pickerFontFamily | string | | Android | | +|pickerFontFamily | string | | iOS/Android | | |pickerRowHeight | number | 24 | iOS | | |pickerData | array | | iOS/Android | | |selectedValue | array | | iOS/Android | | diff --git a/index.d.ts b/index.d.ts index 973fc60..7c70938 100644 --- a/index.d.ts +++ b/index.d.ts @@ -60,7 +60,7 @@ interface PickerOptions { * @type {string} * @memberof PickerOptions */ - pickerCancelBtnText: string + pickerCancelBtnText?: string /** * The color of the text for the confirm button diff --git a/ios/RCTBEEPickerManager/BzwPicker.h b/ios/RCTBEEPickerManager/BzwPicker.h index 0da6fcf..9b19689 100755 --- a/ios/RCTBEEPickerManager/BzwPicker.h +++ b/ios/RCTBEEPickerManager/BzwPicker.h @@ -41,6 +41,7 @@ typedef void(^backBolock)(NSDictionary * ); @property(strong,nonatomic)NSString *rightStr; @property(strong,nonatomic)NSString *pickerToolBarFontSize; @property(strong,nonatomic)NSString *pickerFontSize; +@property(strong,nonatomic)NSString *pickerFontFamily; @property(strong,nonatomic)NSArray *pickerFontColor; @property(strong,nonatomic)NSString *pickerRowHeight; @@ -79,7 +80,7 @@ typedef void(^backBolock)(NSDictionary * ); -(instancetype)initWithFrame:(CGRect)frame dic:(NSDictionary *)dic leftStr:(NSString *)leftStr centerStr:(NSString *)centerStr rightStr:(NSString *)rightStr topbgColor:(NSArray *)topbgColor bottombgColor:(NSArray *)bottombgColor leftbtnbgColor:(NSArray *)leftbtnbgColor rightbtnbgColor:(NSArray *)rightbtnbgColor centerbtnColor:(NSArray *)centerbtnColor selectValueArry:(NSArray *)selectValueArry weightArry:(NSArray *)weightArry - pickerToolBarFontSize:(NSString *)pickerToolBarFontSize pickerFontSize:(NSString *)pickerFontSize pickerFontColor:(NSArray *)pickerFontColor pickerRowHeight:(NSString *)pickerRowHeight; + pickerToolBarFontSize:(NSString *)pickerToolBarFontSize pickerFontSize:(NSString *)pickerFontSize pickerFontColor:(NSArray *)pickerFontColor pickerRowHeight:(NSString *)pickerRowHeight pickerFontFamily:(NSString *)pickerFontFamily; -(void)selectRow; @end diff --git a/ios/RCTBEEPickerManager/BzwPicker.m b/ios/RCTBEEPickerManager/BzwPicker.m index 8002777..41aea4b 100755 --- a/ios/RCTBEEPickerManager/BzwPicker.m +++ b/ios/RCTBEEPickerManager/BzwPicker.m @@ -12,7 +12,7 @@ @implementation BzwPicker -(instancetype)initWithFrame:(CGRect)frame dic:(NSDictionary *)dic leftStr:(NSString *)leftStr centerStr:(NSString *)centerStr rightStr:(NSString *)rightStr topbgColor:(NSArray *)topbgColor bottombgColor:(NSArray *)bottombgColor leftbtnbgColor:(NSArray *)leftbtnbgColor rightbtnbgColor:(NSArray *)rightbtnbgColor centerbtnColor:(NSArray *)centerbtnColor selectValueArry:(NSArray *)selectValueArry weightArry:(NSArray *)weightArry - pickerToolBarFontSize:(NSString *)pickerToolBarFontSize pickerFontSize:(NSString *)pickerFontSize pickerFontColor:(NSArray *)pickerFontColor pickerRowHeight:(NSString *)pickerRowHeight + pickerToolBarFontSize:(NSString *)pickerToolBarFontSize pickerFontSize:(NSString *)pickerFontSize pickerFontColor:(NSArray *)pickerFontColor pickerRowHeight:(NSString *)pickerRowHeight pickerFontFamily:(NSString *)pickerFontFamily { self = [super initWithFrame:frame]; @@ -29,6 +29,7 @@ self.centStr=centerStr; self.pickerToolBarFontSize=pickerToolBarFontSize; self.pickerFontSize=pickerFontSize; + self.pickerFontFamily=pickerFontFamily; self.pickerFontColor=pickerFontColor; self.pickerRowHeight=pickerRowHeight; [self getStyle]; @@ -43,46 +44,34 @@ -(void)makeuiWith:(NSArray *)topbgColor With:(NSArray *)bottombgColor With:(NSArray *)leftbtnbgColor With:(NSArray *)rightbtnbgColor With:(NSArray *)centerbtnColor { UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0,0, self.frame.size.width, 40)]; - view.backgroundColor = [UIColor cyanColor]; - + view.backgroundColor = [self colorWith:topbgColor]; [self addSubview:view]; self.leftBtn = [UIButton buttonWithType:UIButtonTypeCustom]; self.leftBtn.frame = CGRectMake(0, 0, 90, 40); + self.leftBtn.font = [UIFont fontWithName:_pickerFontFamily size:[_pickerToolBarFontSize integerValue]]; + self.leftBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; [self.leftBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, 10.0, 0, 0)]; [self.leftBtn setTitle:self.leftStr forState:UIControlStateNormal]; - [self.leftBtn setFont:[UIFont systemFontOfSize:[_pickerToolBarFontSize integerValue]]]; - self.leftBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; - [self.leftBtn addTarget:self action:@selector(cancleAction) forControlEvents:UIControlEventTouchUpInside]; - [self.leftBtn setTitleColor:[self colorWith:leftbtnbgColor] forState:UIControlStateNormal]; - + [self.leftBtn addTarget:self action:@selector(cancleAction) forControlEvents:UIControlEventTouchUpInside]; [view addSubview:self.leftBtn]; - view.backgroundColor=[self colorWith:topbgColor]; - self.rightBtn = [UIButton buttonWithType:UIButtonTypeCustom]; self.rightBtn.frame = CGRectMake(view.frame.size.width-90,0, 90, 40); + self.rightBtn.font = [UIFont fontWithName:_pickerFontFamily size:[_pickerToolBarFontSize integerValue]]; + self.rightBtn.contentHorizontalAlignment=UIControlContentHorizontalAlignmentRight; [self.rightBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 10.0)]; [self.rightBtn setTitle:self.rightStr forState:UIControlStateNormal]; - self.rightBtn.contentHorizontalAlignment=UIControlContentHorizontalAlignmentRight; - [self.rightBtn setTitleColor:[self colorWith:rightbtnbgColor] forState:UIControlStateNormal]; - - [view addSubview:self.rightBtn]; - [self.rightBtn setFont:[UIFont systemFontOfSize:[_pickerToolBarFontSize integerValue]]]; [self.rightBtn addTarget:self action:@selector(cfirmAction) forControlEvents:UIControlEventTouchUpInside]; + [view addSubview:self.rightBtn]; UILabel *cenLabel=[[UILabel alloc]initWithFrame:CGRectMake(90, 5, SCREEN_WIDTH-180, 30)]; - - cenLabel.textAlignment=NSTextAlignmentCenter; - - [cenLabel setFont:[UIFont systemFontOfSize:[_pickerToolBarFontSize integerValue]]]; - cenLabel.text=self.centStr; - + cenLabel.textAlignment=NSTextAlignmentCenter; + cenLabel.font = [UIFont fontWithName:_pickerFontFamily size:[_pickerToolBarFontSize integerValue]]; [cenLabel setTextColor:[self colorWith:centerbtnColor]]; - [view addSubview:cenLabel]; self.pick = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 40, self.frame.size.width, self.frame.size.height - 40)]; @@ -529,8 +518,9 @@ NSDictionary *dic=[self.dataDry objectAtIndex:i]; NSArray *ary=[dic allKeys]; - - [self.provinceArray addObject:[ary firstObject]]; + if ([ary firstObject]) { + [self.provinceArray addObject:[ary firstObject]]; + } } NSDictionary *dic=[self.dataDry firstObject]; @@ -951,8 +941,7 @@ if (lbl == nil) { lbl = [[UILabel alloc]init]; - //在这里设置字体相关属性 - lbl.font = [UIFont systemFontOfSize:[_pickerFontSize integerValue]]; + lbl.font = [UIFont fontWithName:_pickerFontFamily size:[_pickerFontSize integerValue]]; lbl.textColor = [self colorWith:_pickerFontColor]; lbl.textAlignment = UITextAlignmentCenter; } diff --git a/ios/RCTBEEPickerManager/RCTBEEPickerManager.m b/ios/RCTBEEPickerManager/RCTBEEPickerManager.m index d1fd5e4..0215d49 100644 --- a/ios/RCTBEEPickerManager/RCTBEEPickerManager.m +++ b/ios/RCTBEEPickerManager/RCTBEEPickerManager.m @@ -54,6 +54,7 @@ RCT_EXPORT_METHOD(_init:(NSDictionary *)indic){ NSArray *weightArry=indic[@"wheelFlex"]; NSString *pickerToolBarFontSize=[NSString stringWithFormat:@"%@",indic[@"pickerToolBarFontSize"]]; NSString *pickerFontSize=[NSString stringWithFormat:@"%@",indic[@"pickerFontSize"]]; + NSString *pickerFontFamily=[NSString stringWithFormat:@"%@",indic[@"pickerFontFamily"]]; NSArray *pickerFontColor=indic[@"pickerFontColor"]; NSString *pickerRowHeight=indic[@"pickerRowHeight"]; id pickerData=indic[@"pickerData"]; @@ -79,7 +80,7 @@ RCT_EXPORT_METHOD(_init:(NSDictionary *)indic){ self.height=220; } - self.pick=[[BzwPicker alloc]initWithFrame:CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, self.height) dic:dataDic leftStr:pickerCancelBtnText centerStr:pickerTitleText rightStr:pickerConfirmBtnText topbgColor:pickerToolBarBg bottombgColor:pickerBg leftbtnbgColor:pickerCancelBtnColor rightbtnbgColor:pickerConfirmBtnColor centerbtnColor:pickerTitleColor selectValueArry:selectArry weightArry:weightArry pickerToolBarFontSize:pickerToolBarFontSize pickerFontSize:pickerFontSize pickerFontColor:pickerFontColor pickerRowHeight: pickerRowHeight]; + self.pick=[[BzwPicker alloc]initWithFrame:CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, self.height) dic:dataDic leftStr:pickerCancelBtnText centerStr:pickerTitleText rightStr:pickerConfirmBtnText topbgColor:pickerToolBarBg bottombgColor:pickerBg leftbtnbgColor:pickerCancelBtnColor rightbtnbgColor:pickerConfirmBtnColor centerbtnColor:pickerTitleColor selectValueArry:selectArry weightArry:weightArry pickerToolBarFontSize:pickerToolBarFontSize pickerFontSize:pickerFontSize pickerFontColor:pickerFontColor pickerRowHeight: pickerRowHeight pickerFontFamily:pickerFontFamily]; _pick.bolock=^(NSDictionary *backinfoArry){ @@ -121,7 +122,7 @@ RCT_EXPORT_METHOD(hide){ self.pick.hidden=YES; - return; + return; } RCT_EXPORT_METHOD(select: (NSArray*)data){ diff --git a/package.json b/package.json index 2e4a72d..f2d9f5d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-picker", - "version": "4.3.6", + "version": "4.3.7", "description": "A Native Picker with high performance.", "main": "index.js", "types": "index.d.ts", -- 2.26.2