UIDatePicker example in iOS
In the previous tutorials we have worked around custom UITableViewCell and UIWebView. Now in this tutorial I am going to show you how to implement an UIDatePicker in iOS development.
UIDatePicker is used to select a specific date and time in the iOS app development process. UIDatePicker class implements an object that uses multiple wheels from which user selects date and time. Read apple documentation about UIDatePicker.
Overview
In this tutorial I am going to create an iOS application which displays the user selected date and time from UIDatePicker through UILabel.
Getting Started
Create a new Xcode single view application. Enter the project name as ‘UIDatePickerExample’. Enter the organization name and company identifier details. Select the device as ‘iPhone’. Select next to save the project.
Select the Main.Storyboard file. Drag and drop an UIDatePicker and UILabel over the ‘ViewController’ scene. Now your view should look like this,
Create an IBOutlet for the UILabel and UIDatePicker as ‘selectedDate’ and ‘datePicker’ respectively.
Now create an IBAction for the UIDatePicker as ‘pickerAction’ as below.
Implement Code
Add this code below inside the method ‘pickerAction’ in the file ViewController.m.
1 2 3 4 5 6 7 | NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"dd-MM-yyyy HH:mm"]; NSString *formatedDate = [dateFormatter stringFromDate:self.datePicker.date]; self.selectedDate.text =formatedDate; |
'모바일개발(Mobile Dev) > IOS개발(ObjectC)' 카테고리의 다른 글
블록 객체 정의 (0) | 2015.09.29 |
---|---|
Custom UITableViewCell example in iOS (0) | 2015.09.19 |
Creating Custom UITableViewCell using Nib (.xib) files in XCode (0) | 2015.09.15 |
self.myVar myVar _myVar (0) | 2015.09.15 |
iOS 개발자료 잡동사니 (0) | 2015.09.15 |