添加UIPickerView到UIActionSheet(在底部按钮)(Adding UIPicke

2019-08-31 15:09发布

我想要

  1. 示出了选择器视图(向上滑动)
  2. 停用背景而它的可见
  3. 显示(UIActionSheet)按钮在底部(未在顶部)

在我看来,首先一个简单的解决方案,因为你可以在网页,但所有的解决方案位置到处添加选择器以一个动作片,在顶部的按钮找到代码, 我需要把按钮的动作片的底部(对齐?)。

这可能吗? 我想这是,如果我看: 实例

问候

Jeven

编辑(我的解决方案基于编码爸爸溶液)

UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil
                                                             delegate:nil
                                                    cancelButtonTitle:nil
                                               destructiveButtonTitle:nil
                                                    otherButtonTitles:nil];
    [actionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent];

    CGRect pickerFrame = CGRectMake(0, 0, 0, 0);
    UIPickerView *pickerView = [[UIPickerView alloc]initWithFrame:pickerFrame];
    pickerView.showsSelectionIndicator = YES;
    pickerView.dataSource = self;
    pickerView.delegate = self;

    UISegmentedControl *backButton =  [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"Back", nil]] ;
    [backButton addTarget:self action:@selector(someFunction:) forControlEvents:UIControlEventValueChanged];
    backButton.tintColor = [UIColor colorWithRed:0.10 green:0.20 blue:0.52 alpha:0.5];
    backButton.segmentedControlStyle = UISegmentedControlStyleBar;
    [backButton addTarget:self action:@selector(btnActionCancelClicked:) forControlEvents:UIControlEventAllEvents];
    backButton.frame = CGRectMake(20.0, 220.0, 280.0, 40.0);

    UISegmentedControl *acceptButton =  [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"Accept", nil]] ;
    [acceptButton addTarget:self action:@selector(anotherFunction:) forControlEvents:UIControlEventValueChanged];
    acceptButton.tintColor = [UIColor colorWithRed:0.10 green:0.20 blue:0.52 alpha:0.5];
    acceptButton.segmentedControlStyle = UISegmentedControlStyleBar;
    acceptButton.frame = CGRectMake(20.0, 280.0, 280.0, 40.0);

    [actionSheet addSubview:pickerView];
    [actionSheet addSubview:backButton];
    [actionSheet addSubview:acceptButton];

    [actionSheet showInView:[[UIApplication sharedApplication] keyWindow]];
    [actionSheet setFrame:CGRectMake(0,150,320, 400)]; 

......那么就适用iPhone 5 / iPhone 4的依赖视角大小限制

组织编写了:又一个暗示! 本来我想用标准Actionsheet,但并没有要放置pickerview底部。 我没有找到一个方法如何移动的按钮。 显然,这真的很简单: 添加的UIView作为子视图的UIActionSheet好知道;)

Answer 1:

你有2个possibilites:

选项1:大的调整。

ActionSheet示出了具有初始化期间定义的次序的按钮。 因此,在顶部位置放置一些虚拟按钮和取消将是唯一可见的,其他所有按钮将被pickerview隐藏。 代码(警告-TWEAK在otherButtonTitles):

UIActionSheet *menu = [[UIActionSheet alloc] initWithTitle:@"Actionsheet"
                                                  delegate:self
                                         cancelButtonTitle:@"Cancel"
                                    destructiveButtonTitle:nil
                                         otherButtonTitles:@"1", @"2", @"3", @"4", nil];

UIPickerView *pickerView = [[UIPickerView alloc] init];
pickerView.delegate = self;
pickerView.dataSource = self;

[menu addSubview:pickerView];
[menu showInView:self.view];
[menu setBounds:CGRectMake(0,0,320, 500)];

CGRect pickerRect = pickerView.bounds;
pickerRect.origin.y = 35;
pickerView.frame = pickerRect;

选项2:在自制

menu = [[UIActionSheet alloc] initWithTitle:@"Actionsheet"
                                                  delegate:self
                                         cancelButtonTitle:nil
                                    destructiveButtonTitle:nil
                                         otherButtonTitles:nil];

UIPickerView *pickerView = [[UIPickerView alloc] init];
pickerView.delegate = self;
pickerView.dataSource = self;
CGRect pickerRect = pickerView.bounds;
pickerRect.origin.y = 35;
pickerView.frame = pickerRect;

UIButton *startbtn = [UIButton buttonWithType:UIButtonTypeCustom];
startbtn.frame = CGRectMake(80,230, 170, 73);
[startbtn setBackgroundImage:[UIImage imageNamed:@"yourbutton.png"] forState:UIControlStateNormal];
[startbtn addTarget:self action:@selector(pressedbuttonCancel:) forControlEvents:UIControlEventTouchUpInside];

[menu addSubview:pickerView];
[menu addSubview:startbtn];
[menu showInView:self.view];
[menu setFrame:CGRectMake(0,150,320, 350)];

检查为1选项按钮应在actionsheet除非点击将不会被派往选择方法。



文章来源: Adding UIPickerView to UIActionSheet (buttons at the bottom)