将UIPickerView添加到UIActionSheet

将UIPickerView添加到UIActionSheet

本文介绍了将UIPickerView添加到UIActionSheet(底部的按钮)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想


  1. 显示选择器视图(向上滑动)

  2. 停用背景虽然它是可见的

  3. 显示(UIActionSheet)按钮位于底部(不在顶部)

在我看来,这是一个简单的解决方案,因为您可以找到用于在网络中的任何位置添加选择器视图的代码,但所有解决方案都将按钮放在顶部,我需要将按钮放在底部行动表(对齐?)

It seems to me an easy solution at first since you can find code for adding a picker view to an action sheet everywhere in the web but all solutions position the buttons at top and I need to put the buttons at the bottom of the action sheet (alignment?).

这可能吗?我想如果我看一下:

Is this possible? I guess it is if I look at: Example

问候

Jeven

EDITED(我的解决方案基于编码的爸爸解决方案)

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相关的视图大小限制

... then just apply iPhone 5/iphone 4 dependent view size constraints

编辑2:
只是另一个提示!最初我想使用标准的Actionsheet,但不想将pickerview放在底部。我没有找到如何移动按钮的方法。显然这很简单:很有必要; )

推荐答案

你有2个可能性:

Option1 :大调整。

ActionSheet显示了在init期间定义的顺序的按钮。因此,在顶部放置一些虚拟按钮,取消将是唯一可见的,所有其他按钮将被选择器视图隐藏。代码(在otherButtonTitles上调整警告)

ActionSheet shows the buttons with the order defined during init. So place some dummy buttons at the top and Cancel will be the only visible, all other buttons will be hidden by the pickerview. Code (warning-tweak at 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)];

检查option2按钮应该在动作表上,除非点击不会被分派到选择器方法。

Check that for option2 the button should be on the actionsheet unless the clicks will not be dispatched to the selector method.

这篇关于将UIPickerView添加到UIActionSheet(底部的按钮)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 14:30