欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

iOS中怎么自定義一個日期選擇器-創(chuàng)新互聯(lián)

今天就跟大家聊聊有關(guān)iOS中怎么自定義一個日期選擇器,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結(jié)了以下內(nèi)容,希望大家根據(jù)這篇文章可以有所收獲。

創(chuàng)新互聯(lián)建站主營瑞昌網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營網(wǎng)站建設(shè)方案,app軟件定制開發(fā),瑞昌h5微信平臺小程序開發(fā)搭建,瑞昌網(wǎng)站營銷推廣歡迎瑞昌等地區(qū)企業(yè)咨詢

一、封裝日期選擇器類YCDatePickerView

1、新建一個類,基于UIView,取名YCDatePickerView。

2、YCDatePickerView類中.h文件代碼如下:

typedef void (^MyBasicBlock)(id result);

#import <UIKit/UIKit.h>

@interface YCDatePickerView : UIView

@property (nonatomic, strong) UIButton *btnConfirm;
@property (nonatomic, strong) UIButton *btnCancel;
@property (nonatomic, strong) UIDatePicker *datePicker;
@property (nonatomic, copy) MyBasicBlock selectBlock;

+ (YCDatePickerView *)datePickerViewWithMode:(UIDatePickerMode) datePickerMode bolck:(MyBasicBlock)block;


@end

3、YCDatePickerView類中.m文件代碼如下:

#define SCREEN_WIDTH   [[UIScreen mainScreen] bounds].size.width
#define SCREEN_HEIGHT   [[UIScreen mainScreen] bounds].size.height

#define kTopBarViewHeight    40
#define kButton_Width      40
#define kButton_Height     40
#define kDatePicker_Height   256


#import "YCDatePickerView.h"

@implementation YCDatePickerView

- (id)initWithFrame:(CGRect)frame
{
  self = [super initWithFrame:frame];
  if (self) {

    UIView *topBarView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, kTopBarViewHeight)];
    topBarView.backgroundColor = [UIColor orangeColor];
    [self addSubview:topBarView];

    _btnConfirm = [[UIButton alloc] initWithFrame:CGRectMake(self.frame.size.width-kButton_Width-10, 0, kButton_Width, kButton_Height)];
    [_btnConfirm addTarget:self action:@selector(btnConfirm:) forControlEvents:UIControlEventTouchUpInside];
    [_btnConfirm setTitle:@"確定" forState:UIControlStateNormal];
    [topBarView addSubview:_btnConfirm];

    _btnCancel = [[UIButton alloc] initWithFrame:CGRectMake(10, 0, kButton_Width, kButton_Height)];
    [_btnCancel addTarget:self action:@selector(btnCancel:) forControlEvents:UIControlEventTouchUpInside];
    [_btnCancel setTitle:@"取消" forState:UIControlStateNormal];
    [topBarView addSubview:_btnCancel];

    _datePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(topBarView.frame), self.frame.size.width, self.frame.size.height-kTopBarViewHeight)];
    _datePicker.backgroundColor = [UIColor whiteColor];
    [self addSubview:_datePicker];

  }
  return self;
}

- (void)btnConfirm:(id)sender
{
  if (self.selectBlock) {
    self.selectBlock(self.datePicker.date);
  }
}

- (void)btnCancel:(id)sender
{
  if (self.selectBlock) {
    self.selectBlock(nil);
  }
}

+ (YCDatePickerView *)datePickerViewWithMode:(UIDatePickerMode) datePickerMode bolck:(MyBasicBlock)block
{
  YCDatePickerView *picker = [[YCDatePickerView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, kDatePicker_Height)];
  picker.datePicker.datePickerMode = datePickerMode;
  picker.selectBlock = block;
  return picker;
}

@end

二、YCDatePickerView的使用

1、在ViewController中導(dǎo)入頭文件

#import "YCDatePickerView.h"

2、在ViewController.m中添加如下代碼

#define SCREEN_WIDTH   [[UIScreen mainScreen] bounds].size.width
#define SCREEN_HEIGHT   [[UIScreen mainScreen] bounds].size.height


#import "ViewController.h"
#import "YCDatePickerView.h"

@interface ViewController ()

@property (retain, nonatomic) YCDatePickerView *datePicker;

@end

@implementation ViewController

- (void)viewDidLoad {
  [super viewDidLoad];


  UITextField *begin = [[UITextField alloc] initWithFrame:CGRectMake(10, 70, SCREEN_WIDTH-20, 30)];
  begin.placeholder = @"請輸入開始時間";
  begin.borderStyle = UITextBorderStyleRoundedRect;
  [self.view addSubview:begin];

  __weak ViewController *weakself = self;
  begin.inputView = [YCDatePickerView datePickerViewWithMode:UIDatePickerModeDate
                             bolck:^(NSDate *result) {
                               if (result) {
                                 begin.text = [weakself dateToString:result];
                               }
                               [begin resignFirstResponder];
                             }];


  UITextField *end = [[UITextField alloc] initWithFrame:CGRectMake(10, 120, SCREEN_WIDTH-20, 30)];
  end.placeholder = @"請輸入結(jié)束時間";
  end.borderStyle = UITextBorderStyleRoundedRect;
  [self.view addSubview:end];

  end.inputView = [YCDatePickerView datePickerViewWithMode:UIDatePickerModeDate
                                   bolck:^(NSDate *result) {
                                     if (result) {
                                       end.text = [weakself dateToString:result];
                                     }
                                     [end resignFirstResponder];
                                   }];

}

//日期轉(zhuǎn)為字符串
- (NSString *)dateToString:(NSDate *)date
{
  NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
  NSString *strDate = [dateFormatter stringFromDate:date];
  return strDate;
}

@end

看完上述內(nèi)容,你們對iOS中怎么自定義一個日期選擇器有進(jìn)一步的了解嗎?如果還想了解更多知識或者相關(guān)內(nèi)容,請關(guān)注創(chuàng)新互聯(lián)網(wǎng)站建設(shè)公司行業(yè)資訊頻道,感謝大家的支持。

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)建站aaarwkj.com,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點(diǎn)與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。

新聞標(biāo)題:iOS中怎么自定義一個日期選擇器-創(chuàng)新互聯(lián)
文章位置:http://aaarwkj.com/article18/hoddp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供建站公司、手機(jī)網(wǎng)站建設(shè)、云服務(wù)器、營銷型網(wǎng)站建設(shè)、App開發(fā)企業(yè)網(wǎng)站制作

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都網(wǎng)頁設(shè)計公司
久久久久精品国产亚洲av影院| 精品国产乱码一区二区三区四区| 免费亚洲网站在线观看视频| 日韩不卡永久免费视频观看| 欧美亚洲午夜精品久久久| 亚洲国产成人精品久久精品| 中文字幕精品一区二区三区精品| 日韩看片一区二区三区高清| 日韩精品人妻一区二区网站| 欧美日韩一区二区午夜福利| 午夜福利视频在线观看| 久久夜色一区二区三区| 日韩人妻精品在线一区二区| 亚洲一区二区三区av蜜桃| 国产黄色片网站在线看| 成人短篇在线视频夫妻刺激自拍| 亚洲视频一直看一直爽| 欧美一区二区日韩一区二区| 欧美精品黑人三级精品| 日本久久高清免费观看| 亚乱熟女一区二区三区| 蜜臀久久精品亚洲一区| 国产精品六区久久综合亚洲av| 国产精品黑丝美女91| 成人免费av在线网址| 日本午夜熟女九色视频| 日韩亚洲毛片全在线播放| 国产精品情侣av自拍| jvid视频在线观看免费| 美女性生活免费视频网站| 人妻日韩精品综合一二三四| 午夜欧美日韩精品久久久| 亚洲av在线视频免费播放| 韩国av在线免费观看| 一级片欧美女人性生活片| 国产精品欧美色区福利在线| 尤物视频最新在线观看| 日本一区二区不卡二区| 日韩欧美一区亚洲一区| 亚洲一区二区三区av电影| 少妇太爽高潮在线播放|