Remove the "Today" entry from UIDatePicker - iphone

When using a UIDatePicker in iOS SDK, there is always an entry "Today" at the current date.
That's useful in most cases, but where I need it, it's rather confusing.
Is there a way to:
a) disable the "today"-entry (use regular date instead), and have all entries look the same
or even better
b) disable the "today"-entry (use regular date instead), and color the next day in blue
Further more, the application is for private use only, it's not going to get distributed on the AppStore, which means I could use private APIs (I still would rather avoid them) and I don't need it to be backwards compatible. iOS 4 is fine.

I had a similar problem with the UIDatePicker not matching my requirements exactly (in my case I needed a datepicker without a year wheel). Having a look at the UIDatePicker reference, it doesn't look like you can disable the today entry, so you might be forced to do what I did.
I used a UIPickerView and re-implemented the date selection functionality I needed with that. There are a few things you will need to do to implement your custom date picker:
Implement a UIPickerViewDataSource to set up row titles, dimensions and row counts.
Implement a UIPickerViewDelegate to handle events from your custom picker.
Make sure you update your day wheel when the month wheel changes so you get appropriate days for each month. UIDatePicker does this pretty seamlessly. With limited time, I just reload the picker when the month changes so the day counts match up.

Related

SwiftUI Widget DateStyle Custom Format

Just wondering if there is a way to apply a custom format for the DateStyle comp within SwiftUI's Text UI. For Example just the minutes or seconds like you would when using a DateFormatter. I want to display the dynamic dates for a Widget but it only offers a limited number of options. Why is this and has anyone found a way around this?
Apple talk more about Displaying Dynamic Dates here: https://developer.apple.com/documentation/widgetkit/keeping-a-widget-up-to-date
You won't like this answer, but as of iOS 14, the answer is there's no way to customize the relative style for Text. The relative style is new in iOS 14, and as always, Apple provide the bare minimum feature.
For now, you have only these choices:
Use other Text.DateStyle, if they work for you
Fallback to DateFormatter (and other formatters) with the tradeoff that widget can only refresh couple of times in a day
Hopefully this won't be the answer with iOS 15 or later.

Custom DatePicker with just two components

I want to to use custom datePicker in my project. In Mode date it shows Month,Day and Year, in my case I don't need Year, I just want to display Month and day.
The API does not provide a way to do this. If you want to be able to, please file a report requesting this ability, and it'll hopefully get included in a future release of iOS.
In the meantime, you can make a pretty convincing replica yourself using a UIPickerView.
Im sorry but following the reference of the PickerView
http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIDatePicker_Class/Reference/UIDatePicker.html#//apple_ref/doc/c_ref/UIDatePickerMode
It says that is not possible to do that, so your only option is to implemente yourself the delegate and the datasource, and create the pickerview with the data you need.

Default date picker date no longer works with iOS 5

I have a medical app that allows the user to calculate a patient's age based on date of birth entered with a date picker. For convenience, I set the default date for the date picker object in Interface Builder to 1/1/1950. However, I noticed that in iOS 5 the default date no longer sets when the date picker initially loads. The default date automatically becomes the upper date limit (if that parameter enabled in Interface Builder), or the current date if this upper limit is not enabled. The default date field in Interface Builder still has "1/1/1950" set. The same version of the app on an older device compiled with iOS 4 still works properly, with the date picker scrolling to 1/1/1950 on loading. I very much would appreciate any advice for fixing the problem. Thanks in advance.
In your ViewController's viewDidLoad, log the value of the picker. If it is not set correctly, then you can try setting the value programmatically in viewDidLoad.

UIDatePicker Time gets reset on changing UIDatePicker's mode to UIDatePickerModeTime?

I am using UIDatePicker in my iPhone application.I have kept a button on clicking which the mode of datepicker switches between UIDatePickerModeTime and UIDatePickerModeDate.
When I change the date of datepicker when the mode is UIDatePickerModeDate,the changed date correctly appears when I switch the mode but if I change the time and switch the mode,on again switching the mode to UIDatePickerModeTime resets the time to 12:00 AM.I am not getting why this is happening and what to do for it.Please help.
I have a similar problem. The first time I change from UIDatePickerModeDate to UIDatePickerModeTime, the time was OK. However, when I change back to the ..Date mode and then to the ..Time mode again, the time read 00:00. Thereafter, regardless of the number of mode changes, the time always remained at 00:00. I modeled my UIDatePicker programmatically the same as the UIDatePicker in Apple's UICatalog app. This behavior does not exist in their app.
Taking your lead, I saved the NSDate value from the picker in a retained #property with the intentions of retrieving and resetting the picker upon a UIControl Notification. However, I could not find an event that fired when the picker was changed from Date mode to Time mode. I even tried something like:
[myDatePicker addTarget:self action:#selector(getDateTime:) forControlEvents:UIControlEventAllEvents];
Of course the event fired if I changed the picker's date (or time) but as I mentioned, not when I changed the mode.
I eventually ended up using a UISegmentedControl (same as in the UICatalog app) that targeted the same event method above where I toggled the mode. However, when I reset the picker to the saved NSDate value, the Time remained at 00:00. I then used NSLog to verify that the saved value was OK and discovered that its Time value portion had also changed to 00:00! This was indeed strange since I had not saved a new NSDate value. The original saved value simply changed on it's own!
I'm still investigating the problem and am very close to calling it a bug, especially when a UIDatePicker is added programmatically without a supporting NIB.
Update:
My final solution was almost identical to yours. For some reason, the error continued when the saved date was stored as an NSDate value. Storing it as an NSString and typecasting both ways did the trick:
self.saveDate = (NSString*)self.myDatePicker.date;
...
[self.myDatePicker setDate:(NSDate*)self.saveDate animated:NO];
Also, since I'm retrieving and saving the date to an external device via a GCD dispatch_async block, the property, self. notation was also needed (even on the main_que).
Final conclusion:
I'm now convinced that setting the UIDatePicker date each and every time the picker is accessed is a necessary requirement rather than a bug. Using Apple's UICatalog app, when you set the date to today just once and then switch between Date and Time mode, their app exhibits exactly the same behavior. The date is retained but the time resets to 00:00. if you switch to a mode other than date or time and switch back, all modes will be reset to their floor values.
I used a Date object which I declared as a property in which I stored the date from the date picker when I present the date picker.
I updated the stored date when I changes the date in date picker(Using UIControl Notification)
On changing the mode of the date picker I assigned the same date to the date picker.
I understand this was fairly simple but formerly I was trying the same thing by taking a simple Date object which didn't work.Making it a property did the job for me

iphone : customize the calendar pick up date

My client would like that the user could pick up a date in an iphone app.
He wants that all the days of the month appear. Moreover he would like to switch to the next or previous month. How would it possible to do that ?
Moreover he would like that in the calendar some days of the month (for ex. the 1rst, the 9th and the 15th) appear in a different color.
If it's possible, how could this be done ?
Thank you in advance for your help
Fabio
Currently there isn't a calendar object exposed in the 3.x iPhone SDK.
You can however implement your own. One way would be to implement your own UIView object and handle the painting and reaction to touching manually. Another way would be to implement a calendar as an HTML page and either create a full web application or embed a UIWebView.
http://dblog.com.au/iphone-development/iphone-sdk-tutorial-build-your-very-own-web-browser/