UIPickerView 显示与隐藏

本文介绍了如何在iOS应用中集成并使用UIPickerView控件。通过实例展示了创建UIPickerView、设置代理方法、实现数据源及显示选择指示器的过程。此外还详细解释了如何自定义键盘上的完成按钮,并将其绑定到相关的操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

转载自  http://www.devdiv.com/home.php?mod=space&uid=45444&do=blog&id=6238


UIPickerView* pickerView = [[UIPickerView alloc] init];
[pickerView sizeToFit];
pickerView
.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
pickerView
.delegate = self;
pickerView
.dataSource = self;
pickerView
.showsSelectionIndicator = YES;
self.yourPickerView = pickerView;  //UIPickerView

yourTextField
.inputView = pickerView;

// create a done view + done button, attach to it a doneClicked action, and place it in a toolbar as an accessory input view...
// Prepare done button
UIToolbar* keyboardDoneButtonView = [[UIToolbar alloc] init];
keyboardDoneButtonView
.barStyle = UIBarStyleBlack;
keyboardDoneButtonView
.translucent = YES;
keyboardDoneButtonView
.tintColor = nil;
[keyboardDoneButtonView sizeToFit];

UIBarButtonItem* doneButton = [[[UIBarButtonItem alloc] initWithTitle:@"Done"
    style
:UIBarButtonItemStyleBordered target:self
    action
:@selector(pickerDoneClicked:)] autorelease];

[keyboardDoneButtonView setItems:[NSArray arrayWithObjects:doneButton, nil]];

// Plug the keyboardDoneButtonView into the text field...
yourTextField
.inputAccessoryView = keyboardDoneButtonView;  

[pickerView release];
[keyboardDoneButtonView release];

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值