Date Picker


e>
Here we start Xcode project of ’DatePicker’.Here you can see that’s easy demonstration.

Here we are give you demo video first for your easy to understand.




Step 1-Start your Xcode New Project and ‘Single View Application’.


Step 2-Give your product name ‘DatePickerView Demo’ and give ’Next’ and ‘Create’.

Step 3-Now go into ‘Main.storyboard’ and search into object library ‘date picker’ then you can see bellow type that is dark and drop into simulator.

Step 4-Now set create your simulator bellow type.Here change and set both are buttons.

Step 5- Now give outlets means property by drag and drop same as bellow type.

Step 6-Now give your event name same as bellow type and press ‘connect’.

Step 7-Now go into the ‘ViewController.m’ are write code into ‘viewDidLoad’.

- (void)viewDidLoad {
    [super viewDidLoad];
myDatePicker.hidden = YES;
    dateLabel.text = @"dd/MM/YYYY  hh:mm:aa";
    
    NSDate *today = [NSDate date];
    NSDateFormatter *df = [[NSDateFormatter alloc] init];
    [myDatePicker setDatePickerMode:UIDatePickerModeDateAndTime];
    
    NSString *dateString = [df stringFromDate:today];
    dateString = [NSString stringWithFormat:@"%@",[df stringFromDate:myDatePicker.date]];
    [myDatePicker addTarget:self action:@selector(datePickerChanged:) forControlEvents:UIControlEventValueChanged];
}
- (void)datePickerChanged:(UIDatePicker *)datePicker
{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"dd/MM/YYYY  hh:mm:aa  "];
    
    NSString *strDate = [dateFormatter stringFromDate:datePicker.date];
    dateLabel.text = strDate;
}

Step 8-Now we you get run then your simulator will show bellow type.

Step 9-Now scroll your picker then would be change your date.

Step 10-Now we are hide picker.So, here we are using buttons and write code into ‘viewDidLoad’.

myDatePicker.hidden = YES;

 And the now write codeine both buttons same as bellow type.
- (IBAction)changeDate:(id)sender {
    myDatePicker.hidden = NO;
}

- (IBAction)setDate:(id)sender {
    myDatePicker.hidden = YES;
}


Step 11-Now we you will run then you see bellow type screen.Here your picker is hidden if you want to change your date that time press ‘Change’ button when date is changed then press ‘set’ your picker return be hide. 

Step 12-Here you want to frame around your picker view thats for you want to go your project here bellow give blue darkest area click on them.   

Step 13- Now go into ‘Build Phases’ and into ‘Link Binary With Libraries’ and click on ’+’. 

Step 14-Now add ‘QuartzCore.framework’ 
and add into ‘viewController.h’ bellow class.

#import <QuartzCore/QuartzCore.h>

Step 15-After that write code into ‘ViewController.m’

// border radius
    [myDatePicker.layer setCornerRadius:30.0f];
// border
    [myDatePicker.layer setBorderColor:[UIColor lightGrayColor].CGColor];
    [myDatePicker.layer setBorderWidth:1.5f];
// drop shadow
    [myDatePicker.layer setShadowColor:[UIColor blackColor].CGColor];
    [myDatePicker.layer setShadowOpacity:0.5];
    [myDatePicker.layer setShadowRadius:3.0];
    [myDatePicker.layer setShadowOffset:CGSizeMake(1.0, 1.0)];
here you can see that code bellow picture.

Here you can see all coding of ‘ViewController.m’.
#import "ViewController.h"

@interface ViewController ()
@end
@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    myDatePicker.hidden = YES;
    dateLabel.text = @"dd/MM/YYYY  hh:mm:aa";
    
    NSDate *today = [NSDate date];
    NSDateFormatter *df = [[NSDateFormatter alloc] init];
// border radius
    [myDatePicker.layer setCornerRadius:30.0f];
// border
    [myDatePicker.layer setBorderColor:[UIColor lightGrayColor].CGColor];
    [myDatePicker.layer setBorderWidth:1.5f];
// drop shadow
    [myDatePicker.layer setShadowColor:[UIColor blackColor].CGColor];
    [myDatePicker.layer setShadowOpacity:0.5];
    [myDatePicker.layer setShadowRadius:3.0];
    [myDatePicker.layer setShadowOffset:CGSizeMake(1.0, 1.0)];

    [myDatePicker setDatePickerMode:UIDatePickerModeDateAndTime];
    
    NSString *dateString = [df stringFromDate:today];
    dateString = [NSString stringWithFormat:@"%@",[df stringFromDate:myDatePicker.date]];
    [myDatePicker addTarget:self action:@selector(datePickerChanged:) forControlEvents:UIControlEventValueChanged];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (void)datePickerChanged:(UIDatePicker *)datePicker
{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"dd/MM/YYYY  hh:mm:aa  "];
    
    NSString *strDate = [dateFormatter stringFromDate:datePicker.date];
    dateLabel.text = strDate;
}

- (IBAction)changeDate:(id)sender {
    myDatePicker.hidden = NO;
}

- (IBAction)setDate:(id)sender {
    myDatePicker.hidden = YES;
}

@end


Step 16-NOw you can run project.


Step 17-When you changed date and press ‘set’ button then will hide your picker view.

Here you can see our funny Videos.


Comments

Popular posts from this blog

Dera Sacha Sauda chief Gurmeet Ram Rahim Singh - News Upword