禁用自定义选择器中的特定行
我正在开发一个应用程序,它显示具有以下值的选择器: 1.早上 2.中午 3.晚上
根据当前时间我需要显示相应的值。
如果是下午 3 点,则用户应该只能选择晚上。
现在我的问题是,有什么办法可以使“早上和中午”不可选择。类似于日期选择器,我可以将选项变灰吗?用户应该知道所有选项,但他应该能够根据时间选择选项。
提前致谢。
im developing an application which shows picker with the following values:
1.Morning
2.Noon
3.Evening
Based on the current time i need to show the respective values.
say if its 3PM the use should be able to select only Evening.
Now my questions is, is there any way i could make the "morning and Noon" unselectable. similar to Date picker can i grey out the options?? the user should be aware of all the options but he should be able to select option based on time.
thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您想将选取器视图中的某些值灰显,请使用以下委托 API 来覆盖该位置的视图。
创建一个 UILabel 并将其文本颜色设置为灰色并将其返回为上述 UILabel 的视图。
如果选择了灰色文本,则通过调用以下 API 将动画设置为默认选择。
希望这有帮助。
If you want to grey out some values in picker view, then make use of the following delegate API to override the view for that position.
Create a UILabel and make its text color to grey and return it as view for the above one.
And if the grey text is selected, animate to the default selection by calling the below API.
Hope this helps.
要使选取器中的行变灰,有一个比创建自己的视图更简单的解决方案。那就是使用attributedTitleForRow。
因为如果返回 nil,该函数将回退到 titleForRow,所以您可以为禁用的行返回灰色,并使用标准 titleForRow 返回其余行。举个例子:
您必须忽略其他回复中提到的禁用行的 didSelectRow 。
To gray out rows in a Picker, there is a much easier solution than creating your own View. That is to use attributedTitleForRow.
Because this function will fall back to titleForRow if you return nil, you can return gray for the disabled rows, and use the standard titleForRow to return the rest. As an example :
You'll have to then ignore the didSelectRow for the disabled rows as mentioned in the other replies.