ユーザーがクレジット カードの有効期限の月と年のみを入力する日付ピッカーを表示したいのですが、月と年のオプションのみを表示するピッカーはありますか?
2275 次
1 に答える
0
おそらく、独自のピッカーを作成する必要があります。ただし、サブクラス化する必要はありません。一般的な UIPickerView を使用して、UIPickerViewDelegate/UIPickerViewDataSource
メソッドから適切な値を返すだけです。
または、同じ効果を得るための解決策があります。このコード スニペットを使用するには、"Indentity inspector" の "Custom class" の nib ファイルで UIPickerView を CDatePickerViewEx に置き換える必要があります。
.h ファイル
#import <UIKit/UIKit.h>
@interface CDatePickerViewEx : UIPickerView <UIPickerViewDelegate, UIPickerViewDataSource>
@property (nonatomic, strong, readonly) NSDate *date;
-(void)selectToday;
@end
.m ファイル
#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
于 2012-09-24T06:09:04.413 に答える