91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

iOS自定義UIDatepicker日期選擇器視圖分享

發布時間:2020-09-07 07:19:06 來源:腳本之家 閱讀:360 作者:南山鋤頭 欄目:移動開發

由于項目需要,需要定制一個日期選擇器,找了半天沒找到合適的就自己寫了個demo

自定義UIDatePicker日期選擇器視圖

效果如下:

iOS自定義UIDatepicker日期選擇器視圖分享

iOS自定義UIDatepicker日期選擇器視圖分享

下面貼上相關代碼:

ViewController:

<pre name="code" class="objc">- (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</pre><br>
<pre></pre>
<br>
DatePicker.h<br>
<p><span ></span></p>
<pre code_snippet_id="2093925" snippet_file_name="blog_20170103_2_3524896" name="code" class="objc">#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
</pre><br>
<p></p>
<p class="p1">Datepicker.m<span class="s1"></span></p>
<p class="p1"></p>
<pre code_snippet_id="2093925" snippet_file_name="blog_20170103_3_4070113" name="code" class="objc"><pre code_snippet_id="2093925" snippet_file_name="blog_20170103_3_4070113" name="code" class="objc">#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
</pre><br>
<pre></pre>
<br>
NSDate+Calendar.h<br>
<p></p>
<p class="p1"></p>
<pre code_snippet_id="2093925" snippet_file_name="blog_20170103_4_4657975" name="code" class="objc">#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
</pre>
<p></p>
<p class="p1"><br>
</p>
<p class="p1"><br>
</p>
NSDate+Calendar.m
<p class="p1"></p>
<pre code_snippet_id="2093925" snippet_file_name="blog_20170103_5_503109" name="code" class="objc">#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
</pre><br>
<br>
<br>
<p></p>
     </pre>

以上這篇iOS自定義UIDatepicker日期選擇器視圖分享就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持億速云。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

阿坝县| 泗水县| 邛崃市| 石台县| 抚州市| 成安县| 霍林郭勒市| 土默特右旗| 尉犁县| 南城县| 肥乡县| 安西县| 海丰县| 偃师市| 南川市| 额济纳旗| 嘉荫县| 千阳县| 平阳县| 北碚区| 岢岚县| 鄂伦春自治旗| 修文县| 阿勒泰市| 沽源县| 故城县| 邵武市| 胶南市| 长丰县| 江城| 仲巴县| 类乌齐县| 英山县| 祁门县| 斗六市| 石屏县| 利津县| 灵石县| 大竹县| 阳高县| 宜城市|