带有 UIPickerView 和“完成”、“下一个”、“上一个”按钮的 UIActionSheet

发布于 2024-11-25 00:14:32 字数 316 浏览 1 评论 0原文

我正在尝试实现一个操作表,其中包含选择器视图和分段控制栏,其中包含上一个按钮、下一个按钮和完成按钮,如下图所示 https://i.sstatic.net/SX61b.jpg。我目前可以使它看起来像这样 https://i.sstatic.net/jpljb.jpg。我想知道是否有人可以帮助我将选择器视图放在底部并使其看起来更好一点。感谢您的任何帮助。

i am trying to implement an action sheet that contains a picker view and a segmented control bar with a previous button, next button and done button like the image as follows https://i.sstatic.net/SX61b.jpg. I currently am able to make it look like this https://i.sstatic.net/jpljb.jpg. I was wondering if someone could help me get the picker view to sit on the bottom and just make it look a little better. Thanks for any help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

仙女山的月亮 2024-12-02 00:14:32

除非您的目标是非常旧的 iOS 版本(即早于 3.2 的版本),否则最好的方法是采用完全不同的方法。

从 3.2 开始,任何 UIResponder(包括所有 UIView)都可以从其 inputView 属性返回 UIView,以在视图成为第一响应者时显示该视图而不是键盘。这甚至适用于通常不会成为第一响应者或根本不显示键盘的视图。很简单:

  1. 像设计任何其他视图一样设计弹出视图。
  2. 确保您的小部件视图从 canBecomeFirstResponder 返回 YES。
  3. 确保您的小部件视图从 inputView 返回弹出视图的实例。

更多详细信息请参阅 文档

另外,顺便说一句,如果您使用的是 iPad,您可能应该使用 UIPopoverController 来显示 UIPickerView,而不是使用这些方法。苹果 实际上可能需要此操作

Unless you're targeting very old versions of iOS (i.e. versions earlier than 3.2), the best way to do it is to take a completely different approach.

As of 3.2, any UIResponder (which includes all UIViews) can return a UIView from its inputView property to show that view instead of the keyboard when the view becomes the first responder. This even works for views that normally don't become first responder or don't display the keyboard at all. It's simple:

  1. Design your popup view, as you would any other view.
  2. Ensure that your widget view returns YES from canBecomeFirstResponder.
  3. Ensure that your widget view returns an instance of your popup view from inputView.

More details are available in the documentation.

Also, BTW, if you're on an iPad you should probably use a UIPopoverController to display a UIPickerView instead of either of these methods. Apple may actually require this if you intend to get your app in the app store.

坐在坟头思考人生 2024-12-02 00:14:32

下一个和上一个按钮实际上是在工具栏中将图像显示给segmentedController。为了得到它你必须定义segmentedController和UIToolbar。 H.接下来添加DataSource和UIPickerView
然后在viewDidLoad中创建对象并定义它们的属性。例如:

 if (keyboardToolbar == nil) {
        keyboardToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 44)];
        [keyboardToolbar setBarStyle:UIBarStyleBlackTranslucent];


        segControl = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"Anterior", @"Siguiente", nil]];
        [segControl setSegmentedControlStyle:UISegmentedControlStyleBar];
        [segControl setTintColor:[UIColor blackColor]];
        segControl.frame = CGRectMake(5, 7, 150, 33);
        segControl.momentary = YES;
        [segControl addTarget:self action:@selector(segSelected:) forControlEvents:UIControlEventValueChanged];

        UIBarButtonItem *extraSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];

        UIBarButtonItem *aceptar = [[UIBarButtonItem alloc] initWithTitle:@"Hecho" style:UIBarButtonItemStyleDone target:self action:@selector(cerrarTeclado:)];

        //aceptar.width = 70.0f;

        [keyboardToolbar setItems:[[NSArray alloc] initWithObjects: extraSpace, aceptar, nil]];
        [keyboardToolbar addSubview:segControl];
    }

The next and previous buttons are actually showing your images to segmentedController Within a toolbar. To get it You have to define the segmentedController and UIToolbar on. H. Next add the DataSource and UIPickerView
Then in the viewDidLoad create objects and define Their properties. For example:

 if (keyboardToolbar == nil) {
        keyboardToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 44)];
        [keyboardToolbar setBarStyle:UIBarStyleBlackTranslucent];


        segControl = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"Anterior", @"Siguiente", nil]];
        [segControl setSegmentedControlStyle:UISegmentedControlStyleBar];
        [segControl setTintColor:[UIColor blackColor]];
        segControl.frame = CGRectMake(5, 7, 150, 33);
        segControl.momentary = YES;
        [segControl addTarget:self action:@selector(segSelected:) forControlEvents:UIControlEventValueChanged];

        UIBarButtonItem *extraSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];

        UIBarButtonItem *aceptar = [[UIBarButtonItem alloc] initWithTitle:@"Hecho" style:UIBarButtonItemStyleDone target:self action:@selector(cerrarTeclado:)];

        //aceptar.width = 70.0f;

        [keyboardToolbar setItems:[[NSArray alloc] initWithObjects: extraSpace, aceptar, nil]];
        [keyboardToolbar addSubview:segControl];
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文