简体   繁体   English

如何创建只有两个小时和分钟的列的简单(自定义)时间选择器?

[英]How to create a simple(custom) time picker with just two colomns, hour and minute?

I want to make a simple TimePicker like this : 我想要这样一个简单的TimePicker:

在此处输入图片说明

If I use UITableView then how do I know that middle row/cell is selected ? 如果我使用UITableView,那么我如何知道选择了中间行/单元格? Also the last row/cell will never be in middle. 而且最后一行/单元格永远不会在中间。 Apart from that, It has to be two tableViews as both hour selection and minute selection needs to be separate. 除此之外,它必须是两个tableViews,因为小时选择和分钟选择都需要分开。 If I use two scrollViews , still how to figure out when an item is exactly in the middle and should be considered as selected item. 如果我使用两个scrollViews,仍然如何确定项目何时恰好在中间,应视为已选项目。

I could not find any customization options in the default date time picker. 我在默认日期时间选择器中找不到任何自定义选项。 Secondly , my picker is very simple one, yet I am not able to find a proper method to create this type of picker. 其次,我的选择器非常简单,但是我找不到合适的方法来创建这种类型的选择器。 I cannot use the default picker, because it has different design which is not what I want. 我不能使用默认选择器,因为它具有不同的设计,这不是我想要的。

Any help is appreciated. 任何帮助表示赞赏。 Thanks 谢谢

If I understand you right, you want only time in your picker and design it? 如果我理解正确,那么您只想在选择器中花时间设计一下吗? From storyboard you can select wheather it is "Time", "Date", "Date & time" etc. Just slect your picker and from right select attributes. 在情节提要中,您可以选择“时间”,“日期”,“日期和时间”等。只需选择您的选择器,然后从正确的选择属性中进行选择即可。

在此处输入图片说明

But for design I suggest you to try these lines of codes: 但是对于设计,我建议您尝试以下代码行:

datePicker.backgroundColor = UIColor.whiteColor() //It is for background color

datePicker.setValue(UIColor.whiteColor(), forKeyPath: "textColor")//It is for text color

self.datePicker.performSelector("_setHighlightColor:", withObject:Constants.Colors.mainHeaderColor) //This should be higlight color

And I suggest you to read this topic. 我建议您阅读主题。

Apple have a specific picker specifically for dates and times. 苹果有专门针对日期和时间的特定选择器。

let picker = UIDatePicker()
picker.datePickerMode = UIDatePickerMode.Time

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何分别在“现在”,“ 1分钟前”,“ 1小时前”显示时间 - How to display time 'just now' '1 minute ago' '1 hour ago' respectively 如何将时间值的NSString表示形式转换为包含小时和分钟的两个NSInteger形式? - How can I convert a NSString representation of a time value into two NSInteger's containing the hour and minute? Android:像iOS一样的小时/分钟选择器? - Android: Hour/Minute picker like iOS? 如何创建自定义选择器? 或者 - How to create an Custom picker?? Or 如何在Realm Swift中存储时间间隔(小时:分钟:秒) - How to store a time interval (hour:minute:second) in Realm swift 如何在Titanium IOS时间选择器中显示12小时格式 - How to show 12 hour format in Titanium IOS time picker 如何以编程方式创建iOS Time Picker? - How to create an iOS Time Picker programmatically? iOS如何创建自定义图像选择器/浏览器 - iOS How to create a custom image picker/browser 如何在 flutter 中创建自定义范围选择器? - How to create custom range picker in flutter? 如何在NSDateComponents中使用字符串设置小时/分钟/秒? - How to set hour/minute/second in NSDateComponents with a string?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM