123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- //
- // ShowGenderAlertView.m
- // smartRhino
- //
- // Created by armin on 2019/11/1.
- // Copyright © 2019 tederen. All rights reserved.
- //
- #import "ShowGenderAlertView.h"
- @interface ShowGenderAlertView ()<UIPickerViewDelegate,UIPickerViewDataSource>
- @property (copy, nonatomic) void(^confirmBlock)(NSString *gender);
- @property (copy, nonatomic) void(^cancelBlock)(void);
- @property (strong,nonatomic) IBOutlet UIPickerView *pickView;
- @property (strong,nonatomic) NSString *selectGender;
- @property (strong,nonatomic) IBOutlet NSLayoutConstraint *bottomH;
- @end
- @implementation ShowGenderAlertView
- static UINib *ViewNib = nil;
- + (instancetype)selectView{
- if (ViewNib == nil) {
- ViewNib = [UINib nibWithNibName:@"ShowGenderAlertView" bundle:nil];
- }
- ShowGenderAlertView *alert = [[ViewNib instantiateWithOwner:nil options:nil] lastObject];
- return alert;
- }
- /**
- * 弹出选择性别
- */
- +(instancetype)initShowGenderAlertViewWithGender:(NSString *)genderStr
- confirm:(void (^)(NSString * _Nonnull))confirmBlock
- cancle:(void (^)(void))cancleBlock{
- ShowGenderAlertView *alert = [self selectView];
- [alert setFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
-
- alert.bottomH.constant = 284 + kiphoneXBootomHeight;
-
- //初始默认值
- alert.selectGender = genderStr;
-
- alert.pickView.delegate = alert;
- alert.pickView.dataSource = alert;
-
- if([genderStr isEqualToString:@"男"]){
- [alert.pickView selectRow:0 inComponent:0 animated:NO];
- }else if([genderStr isEqualToString:@"女"]){
- [alert.pickView selectRow:1 inComponent:0 animated:NO];
- }
-
- [alert setStatusBarStyle:UIStatusBarStyleDefault];
- [alert setGesture:YES];
- [alert setConfirmBlock:confirmBlock];
- [alert setCancelBlock:cancleBlock];
- return alert;
- }
- -(IBAction)userDidBackClickAction:(id)sender{
- [self dismissWithAnimation:kAlertAnimationBottom];
- if(self.cancelBlock){
- self.cancelBlock();
- }
- }
- -(IBAction)userDidSureClickAction:(id)sender{
- [self dismissWithAnimation:kAlertAnimationBottom];
- if(self.confirmBlock){
- self.confirmBlock(self.selectGender);
- }
- }
- #pragma mark - dataSouce
- //有几行
- - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
- return 1;
- }
- //行中有几列
- - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
- return 2;
- }
- //列显示的数据
- - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger) row forComponent:(NSInteger)component {
- if(row == 0){
- return @"男";
- }
- return @"女";
- }
- #pragma mark - delegate
- // 选中某一组的某一行
- - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
- switch (row) {
- case 0:
- self.selectGender = @"男";
- break;
- case 1:
- self.selectGender = @"女";
- break;
- default:
- break;
- }
- }
- @end
|