UIPickerView选择并隐藏 [英] UIPickerView select and hide

查看:135
本文介绍了UIPickerView选择并隐藏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何制作一个 UIPickerView 就像带有webview的那个,其中有一个下拉选择框,而不是像通常的网站那样下拉, iphone 将其变为 UIPickerView ,其中包含所有选项。当您选择一个时,检查将在您选择和更改旁边显示下拉框的值。如何将完成按钮放在 UIPickerView 的顶部以关闭 UIPickerView

How do you make a UIPickerView act like the one with a webview wherein there is a drop down selection box and instead of dropping down like usual websites do, the iphone makes it into a UIPickerView with all the selections in. When you select one, a check becomes visible beside your selection and changes the value of the drop box. And how do you put the "Done" button on top of the UIPickerView to dismiss the UIPickerView?

我已经知道 [pickerview setHidden:YES] 是用于隐藏选择器视图的方法。我只是不知道如何在 UIPickerView 中包含完成按钮。

I already know that [pickerview setHidden:YES] is the method to use to hide the pickerview. I just don't know how to include the "Done" button in the UIPickerView.

问候,
Chris

Regards, Chris

推荐答案

完成按钮放在UIToolBar中。

The "Done" button is placed in UIToolBar.

使用以下UIToolBar方法添加完成按钮。

Use the below method of UIToolBar for adding the "Done" buttons.

- (void)setItems:(NSArray *)items animated:(BOOL)animated {

    UIToolbar*  mypickerToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 56)];
    mypickerToolbar.barStyle = UIBarStyleBlackOpaque;
    [mypickerToolbar sizeToFit];

    NSMutableArray *barItems = [[NSMutableArray alloc] init];

    UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
    [barItems addObject:flexSpace];

    UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(DatePickerDoneClick)];
    [barItems addObject:doneBtn];

    [mypickerToolbar setItems:barItems animated:YES];

}

这篇关于UIPickerView选择并隐藏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆