uidatepicker

SwiftUI: how to create custom UIDatePicker

旧时模样 提交于 2020-05-30 08:08:40
问题 I succeeded to create UIDatePicker inside SwifUI, but when I change the date wheel in picker the date value not update, here is my code: struct DatePicker: UIViewRepresentable { @Binding var date: Date func makeUIView(context: Context) -> UIDatePicker { let view = UIDatePicker() view.datePickerMode = .date return view } func updateUIView(_ uiView: UIDatePicker, context: Context) { uiView.date = date } } Then I call it from the view like this: struct SwiftUIView: View { @State var date = Date(

SwiftUI: how to create custom UIDatePicker

这一生的挚爱 提交于 2020-05-30 08:08:29
问题 I succeeded to create UIDatePicker inside SwifUI, but when I change the date wheel in picker the date value not update, here is my code: struct DatePicker: UIViewRepresentable { @Binding var date: Date func makeUIView(context: Context) -> UIDatePicker { let view = UIDatePicker() view.datePickerMode = .date return view } func updateUIView(_ uiView: UIDatePicker, context: Context) { uiView.date = date } } Then I call it from the view like this: struct SwiftUIView: View { @State var date = Date(

Invalid update of a UIDatePicker inside tableView crashing in iOS 13 on rotation

天涯浪子 提交于 2020-05-17 07:06:32
问题 I am adding a UIDatePicker as a table's footer. I have another extension of UITableView which implements traitCollectionDidChange and only does beginUpdates and endUpdates. I am getting the below crash on changing the orientation. *** Assertion failure in -[UIPickerTableView _Bug_Detected_In_Client_Of_UITableView_Invalid_Number_Of_Rows_In_Section:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKitCore_Sim/UIKit-3901.4.2/UITableView.m:2407 2020-05-12 13:35:28.729340+0530 MyApplication

UIDatePicker 15 Minute Increments Swift

不羁的心 提交于 2020-05-14 14:50:07
问题 In swift , I'm wondering how I would use my UIDatePicker to select 15 minute increments. So instead of having hours with 60 minutes, I only want to be able to select 00 minutes, 15 minutes, 30 minutes, and 45 minutes. Here is my current implementation var schedulePicker: UIDatePicker = UIDatePicker() schedulePicker.datePickerMode = UIDatePickerMode.DateAndTime schedulePicker.addTarget(self, action: "handleSchedulePicker:", forControlEvents: UIControlEvents.ValueChanged) textField9.inputView =

Change UIDatePicker selected Date text Color for Dark mode (iOS 13)

你离开我真会死。 提交于 2020-01-23 04:59:09
问题 Having trouble to find out a solution for changing the color of text for the selected Date in iOS 13 dark mode. I know how to change the color of the text of a UIPicker view using code self.timePicker.setValue(UIColor.black, forKeyPath: "textColor") OR using User Defined Runtime Attributes. But nothing is working for changing the selected date color for iOS 13 Dark mode. With background white color and black text color, my date picker-view looks like this: So with changing the text color

Save and Load Data - CoreData

微笑、不失礼 提交于 2020-01-21 07:53:08
问题 I am very new to CoreData and in my iPhone app I want to know how to save some text, then load it back in. But the trick is, loading it back in when the date in the UIDatePicker is the same as when I saved it, like a calendar. Hope you can help in anyway. Its pretty important I learn how to do this fairly soon, so any help is massively appreciated, thanks. UPDATE: Thanks for the replies, especially the for the code sample. However I have some issues understand how this fits together, forgive

UITextField with DatePicker crashes

时光总嘲笑我的痴心妄想 提交于 2020-01-17 06:53:32
问题 I am new to iOS/Swift so please bear with me. I have a TextField, timeTextField, and want to display a TimePicker on click. All this is working property but when another element is selected the app crashes why does it crash? UPDATE 1: updated code code: func setupTimePicker(){ datePickerView.datePickerMode = UIDatePickerMode.time datePickerView.removeFromSuperview() timeTextField.inputView = datePickerView datePickerView.addTarget(self, action: #selector(self.datePickerValueChanged(sender:)),

localizing + customizing the date format of a UIDatePicker

ぃ、小莉子 提交于 2020-01-15 06:50:47
问题 I need to customize and localize the date format of a UIDatePicker 's DateAndTime mode, so that it will display the date numbers in Arabic language plus time in 24 hours format and in Arabic numbers too. the equivalent row in English would be: 2017 11 15 17:00 I've tried all the solutions proposed on SO from changing the locale to changing device language but to no avail. 回答1: Let's breaking it down: For displaying the content of the date picker to be in Arabic language you'd need to set it

Save last datePicker selection

徘徊边缘 提交于 2020-01-15 03:39:28
问题 I have a project with an UIDatePicker . I want that if I change my UIDatePicker value, for example at 9:23, when I restart my app value is still 9:23 and not the default value. How can I do that? Here is my code: @IBOutlet var myDatePicker: UIDatePicker! var datePicker = /* Get Your Date Picker from somewhere */ // Store value using User Defaults let currentDate = datePicker.date NSUserDefaults.standardUserDefaults().setObject(currentDate, forKey: "Current-Date") // Retrieve Value using User

Setting corner radius on UIDatePicker with a background color

和自甴很熟 提交于 2020-01-14 22:55:03
问题 I have a UIDatePicker in my view and have set the background color of the UIDatePicker : self.datePicker.backgroundColor = [UIColor lightTextColor]; self.datePicker.layer.cornerRadius = 10; This successfully puts a background behind the UIDatePicker ( which in iOS7 is essentially transparent ) but fails to make the rounded corners for the background that I am looking for ( I do this same thing for an image on the screen and it works perfectly ). It seems that the corner radius doesn't affect