如何制作仅覆盖屏幕一半的模态日期选择器? [英] How do I make a modal date picker that only covers half the screen?
问题描述
我希望与iPhone通讯录应用中的生日日期设定器具有相同的效果。如何才能在屏幕上显示模态日期选择器。
I want to have the same effect as the birthday date setter in the iPhone contacts app. How do I have a modal date picker come up only halfway on the screen.
我希望日期选择器超过UITableView(就像在iphone联系人应用程序中一样)。我希望UITableView能够在日期选择器后面自由滚动(就像在iphone联系人应用程序中一样)。
I want the date picker to be over a UITableView (like in the iphone contacts app). I would like the UITableView to scroll freely behind the date picker (like in the iphone contacts app).
提前致谢。
推荐答案
到目前为止,实现日期选择器/ uipicker键盘的最佳方法是使用文本字段的输入视图属性:
By far, the best way to achieve a date-picker/uipicker keyboard-like is to use the input view property of a textfield:
-
构建一个包含UITextField的简单自定义UITableViewCell(这很重要,因为问题是关于在表视图中嵌入一个)
Build a simple custom UITableViewCell that contains a UITextField (It's important only because the question was about embedding one in a table view)
@interface pickerCell : UITableViewCell
{
UITextField *txtTextField;
UIPickerView* dtpPicker;
}
将TextField的inputview设置为UIPickerView (确保它们都已分配并初始化):
set the TextField's inputview to be the UIPickerView (Make sure they have both been allocated and initialized first):
txtTextField.inputView = dtpPicker;
你差不多完成了。现在,当文本字段成为第一个响应者(用户点击它)时,将向用户呈现选择器视图。
只需填写您自己的值即可。或者使用日期选择器。
You are almost done. Now when the textfield becomes the first responder (the user tapped it), the user will be presented with a picker view. Just fill it with your own values. or use a date picker.
您可以将选择器的委托/数据源设置为相同的单元格(如果它始终是生日数据单元格)或者具有单元格的superview用数据加载它。无论你做出哪个选择,一定要更新txtTextField.text
You can set the picker's delegate/datasource to the same cell (if it will always be a birthdate cell) or have the cell's superview load it with data. Whichever choice you make, be sure to update the txtTextField.text on
pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
祝你好运!
Elad。
Good luck! Elad.
这篇关于如何制作仅覆盖屏幕一半的模态日期选择器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!