1

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?

Shantanu
  • 3,086
  • 3
  • 25
  • 32

1 Answers1

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