1. 程式人生 > >iOS自定義UIDatepicker日期選擇器檢視

iOS自定義UIDatepicker日期選擇器檢視

由於專案需要,需要定製一個日期選擇器,找了半天沒找到合適的就自己寫了個demo;

自定義UIDatePicker日期選擇器檢視 效果如下:

下面貼上相關程式碼:

ViewController:

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.view.backgroundColor  = [UIColor whiteColor];
    
    if (!_picker || _picker == nil) {
        _picker = [[DatePicker alloc] initWithFrame:CGRectMake(0, 120, 375, 667)];
        _picker.backgroundColor  = [UIColor whiteColor];
        _picker.delegate = self;
        [self.view addSubview:_picker];
        _picker.hidden = YES;
    }
    [self creatCustomButton];
    
}
- (void)creatCustomButton{
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(120, 20, 100, 40);
    [button setTitle:@"日期選擇器" forState:UIControlStateNormal];
    [button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside ];
    [self.view addSubview:button];
}
- (void)buttonAction:(UIButton *)sender
{
    if (!_picker || _picker == nil) {
        _picker = [[DatePicker alloc] initWithFrame:CGRectMake(0, 120, 375, 667)];
        _picker.backgroundColor  = [UIColor whiteColor];
        _picker.delegate = self;
        [self.view addSubview:_picker];
    }else{
        _picker.hidden = NO;

    }
   
}

-(void)DatePickerDelegateEnterActionWithDataPicker:(DatePicker *)picker{
    NSLog(@"======>%@",picker.date);
    NSString *dateStr = [NSString stringWithFormat:@"%@",picker.date];
    [_picker removeFromSuperview];
    _picker = nil;
    [[[UIAlertView alloc]initWithTitle:@"提示" message:dateStr delegate:self cancelButtonTitle:nil otherButtonTitles:@"確定", nil] show];
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end


DatePicker.h
#import <UIKit/UIKit.h>
@protocol DatePickerDelegate;
@interface DatePicker : UIView <UIPickerViewDataSource,UIPickerViewDelegate>
// 按照規範, 請把這些設定為外部不可見的
// 不可見的部分, 請放到.m檔案裡
@property (nonatomic, retain) UIPickerView* yearPicker;     // 年
@property (nonatomic, retain) UIPickerView* monthPicker;    // 月
@property (nonatomic, retain) UIPickerView* dayPicker;      // 日
@property (nonatomic, retain) UIPickerView* hourPicker;     // 時
@property (nonatomic, retain) UIPickerView* minutePicker;   // 分
// 對外可見的
@property (nonatomic, retain) NSDate*   date;       // 當前date
// 不可見的
@property (nonatomic, retain) UIToolbar*    toolBar;        // 工具條
@property (nonatomic, retain) UILabel*      hintsLabel;     // 提示資訊

// 不可見的
@property (nonatomic, retain) NSMutableArray* yearArray;
@property (nonatomic, retain) NSMutableArray* monthArray;
@property (nonatomic, retain) NSMutableArray* dayArray;
@property (nonatomic, retain) NSMutableArray* hourArray;
@property (nonatomic, retain) NSMutableArray* minuteArray;
// 不可見的
@property (nonatomic, assign) NSUInteger yearValue;
@property (nonatomic, assign) NSUInteger monthValue;
@property (nonatomic, assign) NSUInteger dayValue;
@property (nonatomic, assign) NSUInteger hourValue;
@property (nonatomic, assign) NSUInteger minuteValue;
@property (nonatomic, copy) NSString *dateString;

/**
 * 設定預設值為當前時間
 */
-(void)resetDateToCurrentDate;


/**
 * 設定提示資訊
 */
-(void)setHintsText:(NSString*)hints;

/**
 * 點選確定按鈕 // 按照習慣,這個可木有
 */
-(IBAction)actionEnter:(id)sender;

@property (nonatomic, assign) id<DatePickerDelegate>delegate;
@end


@protocol DatePickerDelegate <NSObject>

/**
 * 點選確定後的事件
 */
@optional
-(void)DatePickerDelegateEnterActionWithDataPicker:(DatePicker*)picker;

@end

Datepicker.m

#import "DatePicker.h"
#import "NSDate+Calendar.h"

#define MainHeight [UIScreen mainScreen].bounds.size.height
#define MainWidth [UIScreen mainScreen].bounds.size.width
typedef enum {
    ePickerViewTagYear = 2012,
    ePickerViewTagMonth,
    ePickerViewTagDay,
    ePickerViewTagHour,
    ePickerViewTagMinute
}PickViewTag;

@interface DatePicker (private)
/**
 * 建立資料來源
 */
-(void)createDataSource;

/**
 * create month Arrays
 */
-(void)createMonthArrayWithYear:(NSInteger)yearInt month:(NSInteger)monthInt;
@end


@implementation DatePicker

@synthesize delegate;
@synthesize yearPicker, monthPicker, dayPicker, hourPicker, minutePicker;
@synthesize date;
@synthesize yearArray, monthArray, dayArray, hourArray, minuteArray;
@synthesize toolBar, hintsLabel;

@synthesize yearValue, monthValue;
@synthesize dayValue, hourValue, minuteValue;

#pragma mark -

#pragma mark -
- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:CGRectMake(0, MainHeight - 260, MainWidth, 260)];
    if (self) {
        // Initialization code
        [self setBackgroundColor:[UIColor blackColor]];
        NSMutableArray* tempArray1 = [[NSMutableArray alloc] initWithCapacity:0];
        NSMutableArray* tempArray2 = [[NSMutableArray alloc] initWithCapacity:0];
        NSMutableArray* tempArray3 = [[NSMutableArray alloc] initWithCapacity:0];
        NSMutableArray* tempArray4 = [[NSMutableArray alloc] initWithCapacity:0];
        NSMutableArray* tempArray5 = [[NSMutableArray alloc] initWithCapacity:0];
        
        [self setYearArray:tempArray1];
        [self setMonthArray:tempArray2];
        [self setDayArray:tempArray3];
        [self setHourArray:tempArray4];
        [self setMinuteArray:tempArray5];
        
        // 更新資料來源
        [self createDataSource];
        
        CGFloat pRate = MainWidth/320;
        
        // 建立 toolBar & hintsLabel & enter button
        UIToolbar* tempToolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, MainWidth, 44)];
        [self setToolBar:tempToolBar];
        [self addSubview:self.toolBar];
        //        [toolBar setTintColor:[UIColor lightTextColor]];
        
        UILabel* tempHintsLabel = [[UILabel alloc] initWithFrame:CGRectMake(5, 5, 250, 34)];
        [self setHintsLabel:tempHintsLabel];
        [self.hintsLabel setBackgroundColor:[UIColor clearColor]];
        [self addSubview:self.hintsLabel];
        [self.hintsLabel setFont:[UIFont systemFontOfSize:24.0f]];
        [self.hintsLabel setTextColor:[UIColor whiteColor]];
        
        
        UIButton* tempBtn = [UIButton buttonWithType:UIButtonTypeCustom];
//        [tempBtn setBackgroundImage:[UIImage imageNamed:@"Resourse.bundle/btnNormal.png"] forState:UIControlStateNormal];
//        [tempBtn setBackgroundImage:[UIImage imageNamed:@"Resourse.bundle/btnPressed.png"] forState:UIControlStateNormal];
        [tempBtn setTitle:@"確定" forState:UIControlStateNormal];
        [tempBtn sizeToFit];
        [tempBtn setTitleColor:[UIColor darkTextColor] forState:UIControlStateNormal];
        [tempBtn setCenter:CGPointMake(MainWidth-15-tempBtn.frame.size.width*.5, 22)];
        [tempBtn addTarget:self action:@selector(actionEnter:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:tempBtn];
        
        
        // 初始化各個檢視
        UIPickerView* yearPickerTemp = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 44, 80, 216)];
        [self setYearPicker:yearPickerTemp];
        [self.yearPicker setFrame:CGRectMake(0*pRate, 44, 80*pRate, 216)];
//        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake( 75*pRate, 141 ,20, 20)];
//        label.font = [UIFont systemFontOfSize:18];
//        label.text = @"年";
//        [self addSubview:label];
        
        UIPickerView* monthPickerTemp = [[UIPickerView alloc] initWithFrame:CGRectMake(80, 44, 56*pRate, 216)];
        [self setMonthPicker:monthPickerTemp];
        [self.monthPicker setFrame:CGRectMake(80*pRate, 44, 56*pRate, 216)];
        
        UIPickerView* dayPickerTemp = [[UIPickerView alloc] initWithFrame:CGRectMake(141, 44, 60, 216)];
        [self setDayPicker:dayPickerTemp];
        [self.dayPicker setFrame:CGRectMake(126*pRate, 44, 60*pRate, 216)];
        
        UIPickerView* hourPickerTemp = [[UIPickerView alloc] initWithFrame:CGRectMake(201, 44, 60, 216)];
        [self setHourPicker:hourPickerTemp];
        [self.hourPicker setFrame:CGRectMake(186*pRate, 44, 60*pRate, 216)];
        
        UIPickerView* minutesPickerTemp = [[UIPickerView alloc] initWithFrame:CGRectMake(261, 44, 60, 216)];
        [self setMinutePicker:minutesPickerTemp];
        [self.minutePicker setFrame:CGRectMake(246*pRate, 44, 60*pRate, 216)];
        NSArray *arrar = @[@"年",@"月",@"日",@"時",@"分"];
        UILabel *NameLabel;
        for (int i = 0; i < 5; i++) {
            switch (i) {
                case 0:
                {
                    NameLabel = [[UILabel alloc] initWithFrame:CGRectMake( 75*pRate, 141 ,20, 20)];
                    break;
                }
                case 1:
                {
                    NameLabel = [[UILabel alloc] initWithFrame:CGRectMake( 126*pRate, 141 ,20, 20)];
                    break;
                }
                case 2:
                {
                    NameLabel = [[UILabel alloc] initWithFrame:CGRectMake( 186*pRate, 141 ,20, 20)];
                    break;
                }
                case 3:
                {
                    NameLabel = [[UILabel alloc] initWithFrame:CGRectMake( 246*pRate, 141 ,20, 20)];
                    break;
                }
                case 4:
                {
                    NameLabel = [[UILabel alloc] initWithFrame:CGRectMake( 296*pRate, 141 ,20, 20)];
                    break;
                }

                default:
                    break;
            }
            NameLabel.font = [UIFont systemFontOfSize:18];
            NameLabel.text = [NSString stringWithFormat:@"%@",arrar[i]];
            [self addSubview:NameLabel];

        }
        
        
        
        [self.yearPicker setDataSource:self];
        [self.monthPicker setDataSource:self];
        [self.dayPicker setDataSource:self];
        [self.hourPicker setDataSource:self];
        [self.minutePicker setDataSource:self];
        
        [self.yearPicker setDelegate:self];
        [self.monthPicker setDelegate:self];
        [self.dayPicker setDelegate:self];
        [self.hourPicker setDelegate:self];
        [self.minutePicker setDelegate:self];
        
        
        
        [self.yearPicker setTag:ePickerViewTagYear];
        [self.monthPicker setTag:ePickerViewTagMonth];
        [self.dayPicker setTag:ePickerViewTagDay];
        [self.hourPicker setTag:ePickerViewTagHour];
        [self.minutePicker setTag:ePickerViewTagMinute];
        
        
        [self addSubview:self.yearPicker];
        [self addSubview:self.monthPicker];
        [self addSubview:self.dayPicker];
        [self addSubview:self.hourPicker];
        [self addSubview:self.minutePicker];
        
        [self.yearPicker setShowsSelectionIndicator:YES];
        [self.monthPicker setShowsSelectionIndicator:YES];
        [self.dayPicker setShowsSelectionIndicator:YES];
        [self.hourPicker setShowsSelectionIndicator:YES];
        [self.minutePicker setShowsSelectionIndicator:YES];
        
        
        [self resetDateToCurrentDate];
    }
    return self;
}
#pragma mark - UIPickerViewDataSource
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
    return 1;
}
//- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component{
//    if (ePickerViewTagYear ==  pickerView.tag) {
//        return 60.0f;
//    } else {
//        return 40.0f;
//    }
//}
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
    if (ePickerViewTagYear == pickerView.tag) {
        return [self.yearArray count];
    }
    
    if (ePickerViewTagMonth == pickerView.tag) {
        return [self.monthArray count];
    }
    
    if (ePickerViewTagDay == pickerView.tag) {
        return [self.dayArray count];
    }
    
    if (ePickerViewTagHour == pickerView.tag) {
        return [self.hourArray count];
    }
    
    if (ePickerViewTagMinute == pickerView.tag) {
        return [self.minuteArray count];
    }
    return 0;
}
#pragma makr - UIPickerViewDelegate
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
    if (ePickerViewTagYear == pickerView.tag) {
        return [self.yearArray objectAtIndex:row];
    }
    
    if (ePickerViewTagMonth == pickerView.tag) {
        return [self.monthArray objectAtIndex:row];
    }
    
    if (ePickerViewTagDay == pickerView.tag) {
        return [self.dayArray objectAtIndex:row];
    }
    
    if (ePickerViewTagHour == pickerView.tag) {
        return [self.hourArray objectAtIndex:row];
    }
    
    if (ePickerViewTagMinute == pickerView.tag) {
        return [self.minuteArray objectAtIndex:row];
    }
    return @"";
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
    if (ePickerViewTagYear == pickerView.tag) {
        self.yearValue = [[self.yearArray objectAtIndex:row] intValue];
    } else if(ePickerViewTagMonth == pickerView.tag){
        self.monthValue = [[self.monthArray objectAtIndex:row] intValue];
    } else if(ePickerViewTagDay == pickerView.tag){
        self.dayValue = [[self.dayArray objectAtIndex:row]intValue];
    } else if(ePickerViewTagHour == pickerView.tag){
        self.hourValue = [[self.hourArray objectAtIndex:row]intValue];
    } else if(ePickerViewTagMinute == pickerView.tag){
        self.minuteValue = [[self.minuteArray objectAtIndex:row] intValue];
    }
    if (ePickerViewTagMonth == pickerView.tag || ePickerViewTagYear == pickerView.tag) {
        [self createMonthArrayWithYear:self.yearValue month:self.monthValue];
        [self.dayPicker reloadAllComponents];
    }
    
    NSString* str = [NSString stringWithFormat:@"%04d%02d%02lu%02lu%02lu",self.yearValue, self.monthValue, (unsigned long)self.dayValue, (unsigned long)self.hourValue, (unsigned long)self.minuteValue];
        [self setDate:[self dateFromString:str withFormat:@"yyyyMMddHHmm"]];
}
#pragma mark - 年月日閏年=情況分析
/**
 * 建立資料來源
 */
-(void)createDataSource{
    // 年
    NSInteger yearInt = [[NSDate date] getYear];
    [self.yearArray removeAllObjects];
    for (int i=yearInt ; i<= yearInt + 10; i++) {
        [self.yearArray addObject:[NSString stringWithFormat:@"%d",i]];
    }
    
    // 月
    [self.monthArray removeAllObjects];
    for (int i=1; i<=12; i++) {
        [self.monthArray addObject:[NSString stringWithFormat:@"%d",i]];
    }
    
    
    NSInteger month = [[NSDate date] getMonth];
    
    [self createMonthArrayWithYear:yearInt month:month];
    
    // 時
    [self.hourArray removeAllObjects];
    for(int i=0; i<24; i++){
        [self.hourArray addObject:[NSString stringWithFormat:@"%02d",i]];
    }
    
    // 分
    [self.minuteArray removeAllObjects];
    for(int i=0; i<60; i++){
        [self.minuteArray addObject:[NSString stringWithFormat:@"%02d",i]];
    }
}
#pragma mark -
-(void)resetDateToCurrentDate{
    NSDate* nowDate = [NSDate date];
    [self.yearPicker selectRow:0 inComponent:0 animated:YES];
    [self.monthPicker selectRow:[nowDate getMonth]-1 inComponent:0 animated:YES];
    [self.dayPicker selectRow:[nowDate getDay]-1 inComponent:0 animated:YES];
    
    [self.hourPicker selectRow:[nowDate getHour] inComponent:0 animated:YES];
    [self.minutePicker selectRow:[nowDate getMinute] inComponent:0 animated:YES];
    
    
    [self setYearValue:[nowDate getYear]];
    [self setMonthValue:[nowDate getMonth]];
    [self setDayValue:[nowDate getDay]];
    [self setHourValue:[nowDate getHour]];
    [self setMinuteValue:[nowDate getMinute]];
    
    NSString* str = [NSString stringWithFormat:@"%04d%02d%02d%02d%02d",self.yearValue, self.monthValue, self.dayValue, self.hourValue, self.minuteValue];
    [self setDate:[self dateFromString:str withFormat:@"yyyyMMddHHmm"]];
    self.dateString = [self dateString:self.date];
}
#pragma mark -
-(void)createMonthArrayWithYear:(NSInteger)yearInt month:(NSInteger)monthInt{
    int endDate = 0;
    switch (monthInt) {
        case 1:
        case 3:
        case 5:
        case 7:
        case 8:
        case 10:
        case 12:
            endDate = 31;
            break;
        case 4:
        case 6:
        case 9:
        case 11:
            endDate = 30;
            break;
        case 2:
            // 是否為閏年
            if (yearInt % 400 == 0) {
                endDate = 29;
            } else {
                if (yearInt % 100 != 0 && yearInt %4 ==4) {
                    endDate = 29;
                } else {
                    endDate = 28;
                }
            }
            break;
        default:
            break;
    }
    
    if (self.dayValue > endDate) {
        self.dayValue = endDate;
    }
    // 日
    [self.dayArray removeAllObjects];
    for(int i=1; i<=endDate; i++){
        [self.dayArray addObject:[NSString stringWithFormat:@"%d",i]];
    }
}
#pragma mark - 點選確定按鈕
-(void)actionEnter:(id)sender{
    if (self.date == nil) {
        self.date =[NSDate date];
    }
    NSLog(@"====>%@",self.date);
    if (self.delegate && [self.delegate respondsToSelector:@selector(DatePickerDelegateEnterActionWithDataPicker:)]) {
        [self.delegate DatePickerDelegateEnterActionWithDataPicker:self];
    }
    [self removeFromSuperview];
}
#pragma mark - 設定提示資訊
-(void)setHintsText:(NSString*)hints{
    [self.hintsLabel setText:hints];
}
#pragma mark -
-(void)removeFromSuperview{
    self.delegate = nil;
    [super removeFromSuperview];
}
- (NSDate *)dateFromString:(NSString *)str withFormat:(NSString *)format{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]];
    [dateFormatter  setDateFormat:format];
    
    
    NSDate* dateFromString = [dateFormatter dateFromString:str];
    return dateFromString;
}

- (NSString *)dateString:(NSDate *)date{
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]];
[dateFormatter setDateFormat:@"yyyyy-MM-dd HH:mm:ss"];
NSString *dateString = [dateFormatter stringFromDate:date];
    return dateString;
}

@end


NSDate+Calendar.h
#import <Foundation/Foundation.h>

//標頭檔案部分
@interface NSDate (Calendar)

/**
 *獲取當前月的天數
 */
- (NSUInteger)YHBaseNumberOfDaysInCurrentMonth;
/**
 *獲取本月第一天
 */
- (NSDate *)YHBaseFirstDayOfCurrentMonth;
//下面這些方法用於獲取各種整形的資料
/**
 *確定某天是周幾
 */
-(int)YHBaseWeekly;
/**
 *年月日 時分秒
 */
-(int)getYear;
-(int)getMonth;
-(int)getDay;
-(int)getHour;
-(int)getMinute;
-(int)getSecond;

@end
NSDate+Calendar.m
#import "NSDate+Calendar.h"

@implementation NSDate (Calendar)
-(NSUInteger)YHBaseNumberOfDaysInCurrentMonth{
    return [[NSCalendar currentCalendar] rangeOfUnit:NSDayCalendarUnit inUnit:NSMonthCalendarUnit forDate:self].length;
}
- (NSDate *)YHBaseFirstDayOfCurrentMonth
{
    NSDate *startDate = nil;
    BOOL ok = [[NSCalendar currentCalendar] rangeOfUnit:NSMonthCalendarUnit startDate:&startDate interval:NULL forDate:self];
    NSAssert1(ok, @"Failed to calculate the first day of the month based on %@", self);
    return startDate;
}
-(int)YHBaseWeekly{
    return (int)[[NSCalendar currentCalendar] ordinalityOfUnit:NSDayCalendarUnit inUnit:NSWeekCalendarUnit forDate:self];
}



-(int)getYear{
    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSUInteger unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
    NSDateComponents *dateComponent = [calendar components:unitFlags fromDate:self];
    return (int)dateComponent.year;
}
-(int)getMonth{
    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSUInteger unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
    NSDateComponents *dateComponent = [calendar components:unitFlags fromDate:self];
    return (int)dateComponent.month;
}
-(int)getDay{
    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSUInteger unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
    NSDateComponents *dateComponent = [calendar components:unitFlags fromDate:self];
    return (int)dateComponent.day;
}
-(int)getHour{
    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSUInteger unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
    NSDateComponents *dateComponent = [calendar components:unitFlags fromDate:self];
    return (int)dateComponent.hour;
}
-(int)getMinute{
    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSUInteger unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
    NSDateComponents *dateComponent = [calendar components:unitFlags fromDate:self];
    return (int)dateComponent.minute;
}
-(int)getSecond{
    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSUInteger unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
    NSDateComponents *dateComponent = [calendar components:unitFlags fromDate:self];
    return (int)dateComponent.second;
}
@end



相關推薦

iOS定義UIDatepicker日期選擇檢視

由於專案需要,需要定製一個日期選擇器,找了半天沒找到合適的就自己寫了個demo; 自定義UIDatePicker日期選擇器檢視 效果如下: 下面貼上相關程式碼: ViewController: - (void)viewDidLoad { [super vie

Android定義DataTimePicker 日期選擇

package com.wwj.datetimepicker;import java.text.SimpleDateFormat;import java.util.Calendar;import android.app.Activity;import android.app.AlertDialog;impor

定義橫向日期選擇,可滑動,可點選

佈局檔案比較簡單,直接上程式碼: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas

sizzle分析記錄: 定義偽類選擇

可見性 隱藏物件沒有寬高,前提是用display:none處理的 jQuery.expr.filters.hidden = function( elem ) { // Support: Opera <= 12.12 // Opera reports offsetWidth

定義銀行種類選擇

前言 年前的最後一個開發需求,將之前H5開卡介面轉變成native。意思就是開卡這個需求做成Android原生的介面,就這單單一個介面需要請求 8 個介面!可想邏輯是有多複雜,其中中間有個小需求-「選擇銀行卡」。來看一下UI出圖。 大致就是點選「銀行」彈

Android 定義檔案路徑選擇

文中涉及到檔名稱排序,固定根目錄以及返回上一層在上面,方便選擇等。根據檔案字尾,篩選檔案還沒做。先看效果。 1、效果圖 2、核心程式碼如下 是通過繼承BaseAdapter 完成的,裡面有自定義layout介面。進行管理返回跟目錄以及上一層,方便管理。

Android 定義含有滾動選擇的對話方塊

1.概述 使用LIstView和Dialog實 自定義含有滾動選擇器的對話方塊,可以設定顯示字型的不同顏色,設定字型透明度,設定大小,設定顯示多少項。下面給兩個效果: 顯示7項,字型透明度和大小改變 顯示5項,字型顏色和大小改變

ios定義日期、時間、城市選擇

選擇器,我想大家都不陌生,當需要使用者去選擇某些範圍值內的一個固定值時,我們會採用選擇器的方式。選擇器可以直觀的提示使用者選擇的值範圍、統一資訊的填寫格式,同時也方便使用者快速的進行選擇,比如對於性別,正常情況下就只有男女兩種情況,那這時候用一個選擇器給使用者進行選擇的話,可以避免錯誤資料的輸入,也更方便使用

ios開發 定義日期選擇 PTXDatePickerView

可能有一部分同學在專案中需要用到一個時間選擇器,又不想自己去自定義,那麼在這裡分享一個自定義的時間選擇器。可能直接用在你的專案中不合適,但可以給你提供參考,並快速自定義出一個時間選擇器。 首先描述下該

Android定義DataTimePicker(日期選擇

package com.wwj.datetimepicker; import java.text.SimpleDateFormat; import java.util.Calendar; import android.app.Activity; import android.app.AlertDialog

Android基於wheelView的定義日期選擇(可拓展樣式)

基於wheelView的自定義日期選擇器 專案要求效果圖: 要求 “6月20 星期五” 這一項作為一個整體可以滑動,”7時”、”48分”分別作為一個滑動整體。 系統自帶的DatePicker、TimePicker大家都知道,只有這種效果:

iOS 定義時間選擇 DatePicker

6種時間選擇方式: 年月日、年月日時、年月日時分、時分、日時分、月日時分 呼叫方式 [[DatePicker shareManager]showWithType:PickerTypeDay title:nil time:@"2018:10:31" backT

iOS 定義日期和資料來源選擇控制元件

需求 App開發中經常會有日期選擇(如生日、睡眠定時等)或者省市區選擇等此類功能,通常UI中不會單獨使用UI中的控制元件,而是在UIPickerView的基礎上增加一個取消和確定按鈕 特點 支援常見的選擇型的資料格式 該控制元件集成了 yyyy-M

SpringMVC定義引數繫結日期型別】

前提:由於日期型別有很多種格式,springmvc無法將字串轉換成日期型別,所以需要我們根據業務需求自定義引數繫結! 第一步:自定義引數繫結器---根據介面卡引數繫結器的編碼要求規範開發bean package com.cyn.ssm.converter; impor

7.使用UITableView和UIDatePicker製作一個日期選擇

介紹就不說了, 直接來看吧 已更新到Swift 2.0版本, 支援Xcode7, iOS9 1.搭建介面 PS: 這裡的Controller必須是UITableViewController, 否則的話就會在實現的時候出現很多問題 1.選中UITa

定義Android日期時間選擇控制元件DateTimePickerDialog

ad = new AlertDialog.Builder(activity).setIcon(R.drawable.datetimeicon).setTitle(initDateTime).setView(dateTimeLayout).setPositiveButton("設定",

ios 定義鍵盤的return鍵以及鍵盤的其他一些屬性

variable 位置 arch ext ddr gin character 觸發 hone //初始化textfield並設置位置及大小 UITextField *text = [[UITextField alloc]initWithFrame:CGRectMake(20

時間、日期選擇【安卓3】

ear hour getc enable pic style min 判斷 eight TimePicker(時間選擇器) 方法 描述 Integer getCurrentHour () 返回當前設置的小時 Integer getCurren

Android的日期選擇

pick mon 註意 cells cin 12月 判斷 void 選擇 TimePicker(時間選擇器) 方法 描述 Integer getCurrentHour () 返回當前設置的小時 Integer getCurrentMinute

IOS 定義按鈕(代碼實現)+九宮格

uifont 排列 end uiview height iyu void rec name 在一些下載應用裏整個頁面都是按鈕,有好多好多,但是仔細觀察不難發現他們很有規律。就像下面一樣?? 很有規律的排列在屏幕上,那麽這需要我們怎麽去做能。 正如標題,我們需要了解兩個知