如何制作仅覆盖一半屏幕的模式日期选择器? [英] How do I make a modal date picker that only covers half the screen?

查看:12
本文介绍了如何制作仅覆盖一半屏幕的模式日期选择器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要和 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).

提前致谢.

推荐答案

到目前为止,实现类似 date-picker/uipicker 键盘的最佳方法是使用文本字段的 input 视图属性:

By far, the best way to achieve a date-picker/uipicker keyboard-like is to use the input view property of a textfield:

  1. 构建一个包含 UITextField 的简单自定义 UITableViewCell(这很重要,因为问题是关于将一​​个嵌入到表格视图中)

  1. 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.

    您可以将选择器的委托/数据源设置为同一个单元格(如果它始终是生日单元格)或让单元格的超级视图加载数据.无论您做出何种选择,请务必更新

    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
    

  • 祝你好运!艾拉德.

    这篇关于如何制作仅覆盖一半屏幕的模式日期选择器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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