In iOS swift 2.0 generally programmers use text validate date using simple text field. But a programmer want to validate date using date picker, then this could be a little tough task. Using date picker you can only justify time and date but can’t validate Date. Here expert developer at Inwizards, leading software development company has shared a simple validation task with code, that would help you to validate date using Date picker in Swift 2.0.
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var DOBTextField:UITextField!
@IBOutlet weak var datePicker:UIDatePicker!
@IBOutlet weak var PickerBackgroundView:UIView!
@IBOutlet weak var Status: UILabel!
var formatter = NSDateFormatter()
override func viewDidLoad() {
super.viewDidLoad()
formatter.dateFormat = “MMM dd,yyyy”
}
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(true)
self.initializeTextFieldInputView()
}
func initializeTextFieldInputView(){
self.datePicker.backgroundColor = UIColor.whiteColor()
self.datePicker.datePickerMode = UIDatePickerMode.Date
self.DOBTextField.inputView = self.PickerBackgroundView
self.PickerBackgroundView.removeFromSuperview()
}
func textFieldShouldBeginEditing(textField: UITextField) -> Bool {
if (textField == self.DOBTextField){
self.datePicker.hidden = false
}else{
self.datePicker.hidden = true
}
return true
}
@IBAction func buttonDone(sender:AnyObject){
self.view.endEditing(true)
let Currentdate:NSDate = NSDate()
let ageComponents:NSDateComponents = NSCalendar.currentCalendar().components(NSCalendarUnit.Year, fromDate:self.datePicker.date, toDate: Currentdate, options: NSCalendarOptions.init(rawValue: 0))
if (ageComponents.year < 18){
self.Status.text = “Date of birth is invalid”
let alert = UIAlertView(title: “Alert”, message: “You must be 18 years of age or older. Sorry, this is required by law.”, delegate: self, cancelButtonTitle: “OK”)
alert.show()
}else{
self.Status.text = “Date of birth is valid”
self.DOBTextField.text = formatter.stringFromDate(self.datePicker.date)
}
}
}
Here I am sharing my code sample which on my GithHub repository.
If you are looking for Software development Services? Consult Inwizards
I do not know whether it’s just me or if perhaps everybody else experiencing issues with your blog.
It looks like some of the text within your content are running off the screen. Can somebody else please comment and let
me know if this is happening to them too? This might be a
issue with my browser because I’ve had this happen previously.
Kudos
Do you mind if I quote a couple of your posts as long as
I provide credit and sources back to your blog?
My website is in the very same niche as yours and my users would truly benefit from
a lot of the information you present here.
Please let me know if this alright with you. Many thanks!
each time i used to read smaller articles that also clear their motive, and that is also happening with this article which I am reading here.
I have been browsing online greater than 3 hours today, but I never found any fascinating article like yours. It’s beautiful worth sufficient for me. In my view, if all site owners and bloggers made excellent content material as you probably did, the internet can be a lot more useful than ever before.
Do you have a spam issue on this website; I also am a blogger, and I was curious about your situation; many of us have created some nice methods and we are looking to exchange strategies with other folks, why not shoot me an e-mail if interested.
Greate article. Keep writing such kind of information on your site. Im really impressed by your blog.
I feel that is among the such a lot vital info for me. And i am satisfied studying your article. But wanna statement on few common things, The web site taste is perfect, the articles is actually nice : D. Excellent task, cheers
You really make it seem so easy with your presentation but I find this topic to be actually something that I think I would never understand. It seems too complex and extremely broad for me. I’m looking forward for your next post, I’ll try to get the hang of it!
It’s really a nice and useful piece of information. I’m glad that you just shared this helpful information with us. Please stay us informed like this. Thanks for sharing.
Somebody essentially help to make seriously articles I would state. This is the first time I frequented your web page and so far? I amazed with the research you made to make this particular submit extraordinary. Magnificent job!
This site was… how do I say it? Relevant!! Finally I have found something which helped me. Thanks!
I needed to thank you for this great read!! I absolutely loved every bit of it. I have you saved as a favorite to look at new things you post…
Thanks a bunch for sharing this with all of us you actually recognize what you are speaking about! Bookmarked. Kindly additionally consult with my web site =). We can have a hyperlink change arrangement between us
great points altogether, you just received a new reader. What may you suggest about your post that you simply made some days in the past? Any sure?
And with that she exited. He was wearing a dark black evening suit and looked wonderful.
Someone necessarrily help too make seriously posts I’d state.
That is the very first time I frequented your web page and up to now?
I surprised with the analysis you made to make this particular publish extraordinary.
Fantastic activity!
Throughout this grand design of things you’ll get an A for effort and hard work. Where you lost everybody was first in your details. You know, it is said, the devil is in the details… And that could not be much more true right here. Having said that, allow me reveal to you exactly what did do the job. The article (parts of it) is definitely highly engaging and this is possibly why I am making the effort to comment. I do not really make it a regular habit of doing that. 2nd, whilst I can see the leaps in reason you make, I am definitely not convinced of how you appear to unite your ideas which in turn make the actual final result. For now I will yield to your point but hope in the foreseeable future you connect the facts better.
I am continually browsing online for articles that can aid me. Thank you!
Hiya! Quick question that’s completely off topic. Do you know how to make your site mobile friendly? My weblog looks weird when browsing from my apple iphone. I’m trying to find a theme or plugin that might be able to correct this issue. If you have any suggestions, please share. Many thanks!
hello there and thank you for your information – I’ve certainly picked up something new from right here. I did however expertise some technical issues using this site, as I experienced to reload the website many times previous to I could get it to load correctly. I had been wondering if your hosting is OK? Not that I’m complaining, but sluggish loading instances times will very frequently affect your placement in google and could damage your high-quality score if ads and marketing with Adwords. Anyway I’m adding this RSS to my e-mail and can look out for a lot more of your respective fascinating content. Make sure you update this again soon..
I and also my guys were found to be going through the good solutions found on your web page then quickly got a horrible feeling I never expressed respect to you for those tips. My men became excited to read all of them and have seriously been enjoying those things. Thanks for getting well accommodating as well as for picking out some smart resources most people are really desperate to be aware of. Our own honest regret for not expressing gratitude to you sooner.
I started off telling about the benefits of our product,but i could tell he
wasn t listening to word i was saying. the man below, his
cock slick with her juices, thrusted incessantly across her
trimmed mound and up to her navel, his cock and
balls rubbing along her clit with every stroke.
One thing I would like to say is that before obtaining more computer system memory, consider the machine directly into which it could well be installed. When the machine is definitely running Windows XP, for instance, the particular memory ceiling is 3.25GB. The installation of more than this would merely constitute a waste. Make certain that one’s mother board can handle this upgrade quantity, as well. Great blog post.
I was more than happy to seek out this web-site.I wished to thanks for your time for this glorious read!! I undoubtedly enjoying every little little bit of it and I’ve you bookmarked to take a look at new stuff you weblog post.
Hello! This is my first visit to your blog! We are a team of volunteers and starting a new initiative in a community in the same niche. Your blog provided us useful information to work on. You have done an outstanding job.
Excellent blog post. I absolutely appreciate this website.
Continue the good work!