Updated 14 December 2016
When we use UIPickerView in  iOS, we can’t see the other fields due to the height of the  UIPickerView.So it’s better to launch the UIPickerView  from the bottom of  the screen, so we can also see the other fields of the UIPickerView and its look good from the simple UIPickerView.To display the PickerView you have to add new view that will attach to bottom of the Screen
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 |
float height= [[UIScreen mainScreen] bounds].size.height; UIView *sortBlock = [[UIView alloc]initWithFrame:CGRectMake(10, 2*(height/3), SCREEN_WIDTH-20, height/3)]; [sortBlock setBackgroundColor : [GlobalData colorWithHexString:NavigationColor]]; sortBlock.layer.cornerRadius = 4; sortBlock.tag = 500; sortBlock.layer.cornerRadius = 20; sortBlock.layer.masksToBounds = YES; UIPickerView *sortPicker = [[UIPickerView alloc] initWithFrame:CGRectMake(0, sortBlock.frame.size.height/6 , SCREEN_WIDTH-20, sortBlock.frame.size.height-20)]; sortPicker.tag = 821; sortPicker.showsSelectionIndicator = YES; // sortPicker.backgroundColor = [UIColor blueColor]; sortPicker.hidden = NO; sortPicker.delegate = self; [sortBlock sortPicker]; UILabel *cancel = [[UILabel alloc] initWithFrame:CGRectMake(10, 5, 80, 30)]; [cancel setTextColor:[UIColor blueColor]]; [cancel setBackgroundColor:[UIColor clearColor]]; [cancel setFont:[UIFont fontWithName: @"Trebuchet MS" size: 20.0f]]; [cancel setText:@"Cancel"]; [sortBlock addSubview:cancel]; UITapGestureRecognizer* cancelGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(cancelbtn:)]; // if labelView is not set userInteractionEnabled, you must do so [cancel setUserInteractionEnabled:YES]; [cancel addGestureRecognizer:cancelGesture]; UILabel *done = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - 80, 5, 80, 30)]; [done setTextColor:[UIColor blueColor]]; [done setBackgroundColor:[UIColor clearColor]]; [done setFont:[UIFont fontWithName: @"Trebuchet MS" size: 20.0f]]; [done setText:@"Done"]; [sortBlock addSubview:done]; UITapGestureRecognizer* doneGesture1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(donebtn:)]; // if labelView is not set userInteractionEnabled, you must do so [done setUserInteractionEnabled:YES]; [done addGestureRecognizer:doneGesture1]; [self.view addSubview:sortBlock]; |
If you have more details or questions, you can reply to the received confirmation email.
Back to Home
Be the first to comment.