Datepiker control implementation in iphone

Leave a Comment
Datepiker control complete implementation code with example in iphone. This complete demo will give you complete source code with code snaps .


devangViewController .h header file

#import <UIKit/UIKit.h>
@interface devangViewController : UIViewController
@property (weak, nonatomic) IBOutlet UILabel *dateLabel;
@property (weak, nonatomic) IBOutlet UIDatePicker *datepiker_outlet;
- (IBAction)datepiker_select:(id)sender;
@end 
devangViewController .m

 #import "devangViewController.h"

@interface devangViewController ()
@end
@implementation devangViewController
@synthesize dateLabel;
@synthesize datepiker_outlet;
- (void)viewDidLoad
{
    [super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
    NSDateFormatter *df = [[NSDateFormatter alloc] init];
    [df setDateFormat:@"MM/dd/yyyy"];
    NSString *formattedDate = [df stringFromDate:datepiker_outlet.date];
   
    dateLabel.text=[NSString stringWithFormat:@"%@" ,formattedDate];
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)datepiker_select:(id)sender {
   
    NSDateFormatter *df = [[NSDateFormatter alloc] init];
    [df setDateFormat:@"MM/dd/yyyy"];
    NSString *formattedDate = [df stringFromDate:datepiker_outlet.date];
   
    dateLabel.text=[NSString stringWithFormat:@"%@" ,formattedDate];
}
@end

Output:

Here is the complete source code also.

Download Source code

0 comments:

Post a Comment