How to set custom date display on UIDatePicker? - ios

I have added a UIDatePicker from storyboard. By default picker shows me the date format as (October - 26 - 2017). But i want the format to be dispayed as (26 - 10 - 2017 ).I am not able to display date in this format on UIDatePicker.Please tell me how can i do this?

You can't do this.
From Apple's documentation for: UIKit > Views and Controls > UIDatePicker
Appearance
The appearance of UIDatePicker is not customizable.
The only thing Apple allows you to change is the date picker mode, which is not what you want. To change the layout to "dd-mm-yyyy", you will need build your own customized picker.
The way I'd suggest going about this, is instead of using UiDatePicker, to use UIPicker. Then, create and assign to that picker a unique class, which inherits from UIPickerView. This way you can customize it exactly how you want. Here is a helpful link for how to get all dates between a range (which is how UIDatePicker() is populated) - Swift: Print all dates between two NSDate()

Related

Customisation in FScalendar view?

Is it possible to do this kind of customization in FSCalender View as below image?
FSCalender provides us round circle layout on the selection of date which is in left.
but
I need the layout like right end side when selecting a date it also selects the day of that date with square border.
In the documentation you can find how to make the shape a rectangle:
https://github.com/WenchaoD/FSCalendar/blob/master/MOREUSAGE.md#the-day-shape-doesnt-have-to-be-a-circle
There are more properties to change apprearance declared here:
https://github.com/WenchaoD/FSCalendar/blob/master/FSCalendar/FSCalendarAppearance.h
Especially borderSelectionColor might be what you are looking for.
yes you can add custom image in FSCalendar

How to Create a UITextField to accommodate value in this following manner?

I am developing an ios application that has two input fields that for entering date. I am planning to add a UIDatePicker in the following manner
[_datePicker setFrame:CGRectMake([UIScreen mainScreen].bounds.size.width-_datePicker.bounds.size.width, [UIScreen mainScreen].bounds.size.height-_datePicker.bounds.size.height, _datePicker.frame.size.width, _datePicker.frame.size.height)];
_inputText.inputView=_datePicker;
But the bigger problem is, I need it to look something like the image I have posted
How can I accomplish this?
Okay... there should be a couple ways to solve this.
1)
Put a transparent (or clear colored) UIButton over the view with the date labels. You may need to make the view containing the labels change color/alpha something to indicate the button has been touched before bringing up the date picker.
2)
If the above doesn't work, try adding the view with the labels as a subview into UIButton.

Changing UIDatePicker

I want to make a datePicker like the one in picture given below:
By UIDatePicker, as long I searched I think UIDatePicker doesn't provide this view. So, I have designed the above view by UIPickerView but my code is very messy and there are other requirements too with the picker now. Can you suggest some library for it?
using a UIDatePicker it is possible by changing the datePickerMode property:
datePicker.datePickerMode = UIDatePickerModeDateAndTime;
More on the documentation
Also, if you want to change the order, you can set the localeproperty with a locale that has a different date format.

Restrict UIDate View from scrolling to old date? [duplicate]

This question already has answers here:
UIDatePicker, setting maximum and minimum dates based on todays date
(8 answers)
Closed 8 years ago.
How to restrict UIDate View from scrolling to old dates(past dates)?
UIDate View should show old dates but not able to select or scroll toward them like disabling them from scrolling to old dates. It should only scroll to new dates(upcoming dates).
i can't set it to minimum date because i have to take current date and it is not possible for my app to set it to minimum date.
If it is not possible with the given function. How can i make it custom or how can i programmatically ?
If you're referring to a UIDatePicker, you can set the minimumDate property. I know you said you wanted to "show old dates" without being able to scroll towards them, but I don't think that's possible with the standard UIDatePicker class.
If it's absolutely necessary to implement this the way you've described you could always roll your own implementation and add that functionality.
#property (weak, nonatomic) IBOutlet UIDatePicker *dpDob;
NSDate *localDate=[NSDate date];
dpDob.minimumDate = localDate ;
You can set it programmatically like this or from xib :)

Disable / Enable UIDatepicker

Is there any disable/enable function in Xcode, i have already tried the hidden function but that really doesn't suit my needs. I'm trying to turn off my UIDatepicker if a uiswitch has been toggled and if it isn't toggled i want it shown. hiding this still outputs todays date to my mail composer. Is there anyway to do this?
Make sure you have a property (IBOutlet) for your UIDatepicker in your .h file
then you can simply do like this:
DatePickerNamed.userInteractionEnabled = YES;
DatePickerName.userInteractionEnabled = NO;
In addition to that I also turn down the alpha value for buttons and switches, if I disable them, so there is also a visual feedback that they're inactive.

Resources