Add UIPickerView & a Button in Action sheet - How?

后端 未结 11 1417
遥遥无期
遥遥无期 2020-11-22 15:40

My application requires following things to be added in an action sheet.

  • UIToolbar
  • Button on UIToolbar
  • UIPicker Control

I have

11条回答
  •  有刺的猬
    2020-11-22 16:34

    One more solution:

    • no toolbar but a segmented control (eyecandy)

      UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil 
                                                          delegate:nil
                                                          cancelButtonTitle:nil
                                                          destructiveButtonTitle:nil
                                                          otherButtonTitles:nil];
      
      [actionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent];
      
      CGRect pickerFrame = CGRectMake(0, 40, 0, 0);
      
      UIPickerView *pickerView = [[UIPickerView alloc] initWithFrame:pickerFrame];
      pickerView.showsSelectionIndicator = YES;
      pickerView.dataSource = self;
      pickerView.delegate = self;
      
      [actionSheet addSubview:pickerView];
      [pickerView release];
      
      UISegmentedControl *closeButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:@"Close"]];
      closeButton.momentary = YES; 
      closeButton.frame = CGRectMake(260, 7.0f, 50.0f, 30.0f);
      closeButton.segmentedControlStyle = UISegmentedControlStyleBar;
      closeButton.tintColor = [UIColor blackColor];
      [closeButton addTarget:self action:@selector(dismissActionSheet:) forControlEvents:UIControlEventValueChanged];
      [actionSheet addSubview:closeButton];
      [closeButton release];
      
      [actionSheet showInView:[[UIApplication sharedApplication] keyWindow]];
      
      [actionSheet setBounds:CGRectMake(0, 0, 320, 485)];
      

提交回复
热议问题