I want to show a date picker where the user will enter only month and year of the credit card expiry date.Is there any picker which will show only month and year options?
Asked
Active
Viewed 2,309 times
1
-
1You can try following link:http://stackoverflow.com/questions/3348247/uidatepicker-select-month-and-year – Nuzhat Zari Sep 24 '12 at 06:13
1 Answers
0
You probably need to make your own picker. You don't have to subclass it or anything, though; just use a generic UIPickerView and return appropriate values from your UIPickerViewDelegate/UIPickerViewDataSource
methods.
Or Here is a solution to get the same effect. For using this snippet of code you should replace UIPickerView to CDatePickerViewEx in nib file in "Custom class" of "Indentity inspector".
.h file
#import <UIKit/UIKit.h>
@interface CDatePickerViewEx : UIPickerView <UIPickerViewDelegate, UIPickerViewDataSource>
@property (nonatomic, strong, readonly) NSDate *date;
-(void)selectToday;
@end
.m file
#import "CDatePickerViewEx.h"
// Identifiers of components
#define MONTH ( 0 )
#define YEAR ( 1 )
// Identifies for component views
#define LABEL_TAG 43
@interface CDatePickerViewEx()
@property (nonatomic, strong) NSIndexPath *todayIndexPath;
@property (nonatomic, strong) NSArray *months;
@property (nonatomic, strong) NSArray *years;
-(NSArray *)nameOfYears;
-(NSArray *)nameOfMonths;
-(CGFloat)componentWidth;
-(UILabel *)labelForComponent:(NSInteger)component selected:(BOOL)selected;
-(NSString *)titleForRow:(NSInteger)row forComponent:(NSInteger)component;
-(NSIndexPath *)todayPath;
-(NSInteger)bigRowMonthCount;
-(NSInteger)bigRowYearCount;
-(NSString *)currentMonthName;
-(NSString *)currentYearName;
@end

IronManGill
- 7,222
- 2
- 31
- 52
-
how do we use CDatePickerViewEx to change the value of the text field when the person selects a month/year? – Kermit the Frog Dec 16 '12 at 21:38
-
Hi Gill-The IronMan, How can I use this code. Can you give the exact link for this code. – Mani Mar 18 '13 at 06:32