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

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 :)

Related

How to set custom date display on UIDatePicker?

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()

Misuse of UITextField.inputView to get similar popup behavior of keyboard

I often want to put my own things in the same place the keyboard pops up, but for my own controls... such as putting a UIDatePicker there, or a custom UIPickerView, or whatever.
I came up with a clumsy way of getting this behavior by having a dummy UITextField and putting my custom view in its inputView property. Then when the user clicks on my item, I just trigger off the UITextField to display the view I've assigned to the inputView.
Then I got to wondering if there was a better less kludgey way to do this. I found this article Show UIPickerView like a keyboard, without UITextField where several people recommend the same thing I do.
My question is this. Is it common to (mis)use the UITextField in this manner?
Many times you will face a UITextfield that you would want to populate through a custom control other than the standrd keyboard. Thus the inputView method was declared and can be used.
What is recommended:
1- if the UItextfield is normal, use the keybard (don't change the input view)
2- if the value is numeric, show the numberpad in keyboard directly (textField.keyboardType = .numberPad)
3- if your textField is a date then you set the input view as a date picker.
4- sometimes you need a UITextField where you need to choose between stuff. Thus you develop your own custom UIPicker and set it as an input View.
5- If what you are tring to achieve don't fall in all the above then you can do your own inputView and assign it.
So in short don't be afraid, it is the normal thing to do!
Hope this helps!

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.

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