最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

iOS自定義UIDatePicker日期選擇器視圖

 更新時(shí)間:2019年04月28日 11:53:41   作者:hero_wqb  
這篇文章主要為大家詳細(xì)介紹了iOS自定義UIDatePicker日期選擇器視圖,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

iOS自定義UIDatePicker日期選擇器視圖 ,首先看一下效果圖:

下面貼上相關(guān)代碼:

ViewController:

#import <UIKit/UIKit.h>
 
@interface ViewController : UIViewController
 
@end
 
 
#import "ViewController.h"
#import "HWDatePicker.h"
 
#define mainW [UIScreen mainScreen].bounds.size.width
#define mainH [UIScreen mainScreen].bounds.size.height
 
@interface ViewController ()<UITextFieldDelegate, HWDatePickerDelegate>
 
@property (nonatomic, weak) HWDatePicker *datePicker;
@property (nonatomic, strong) UITextField *dateTextField;
 
@end
 
@implementation ViewController
 
- (void)viewDidLoad {
 [super viewDidLoad];
 
 self.view.backgroundColor = [UIColor blackColor];
 
 //創(chuàng)建控件
 [self creatControl];
}
 
- (void)creatControl
{
 //textField
 _dateTextField = [[UITextField alloc] initWithFrame:CGRectMake(mainW * 0.05, mainW * 0.72, mainW * 0.9, mainW * 0.12)];
 _dateTextField.background = [UIImage imageNamed:@"textFieldBj"];
 _dateTextField.textAlignment = NSTextAlignmentRight;
 _dateTextField.placeholder = @"請(qǐng)?jiān)O(shè)置日期";
 _dateTextField.delegate = self;
 UILabel *lab2 = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, mainW * 0.4, mainW * 0.12)];
 lab2.textAlignment = NSTextAlignmentLeft;
 lab2.text = @" 日期";
 lab2.textColor = [UIColor grayColor];
 _dateTextField.leftView = lab2;
 _dateTextField.leftViewMode = UITextFieldViewModeAlways;
 UILabel *lab22 = [[UILabel alloc] initWithFrame:CGRectMake(mainW * 0.12 - 15, 0, 15, mainW * 0.12)];
 _dateTextField.rightView = lab22;
 _dateTextField.rightViewMode = UITextFieldViewModeAlways;
 [self.view addSubview:_dateTextField];
 
 //日期選擇器
 HWDatePicker *datePicker = [[HWDatePicker alloc] initWithFrame:CGRectMake(mainW * 0.05, mainH, mainW * 0.9, mainW * 0.5)];
 datePicker.delegate = self;
 [self.view addSubview:datePicker];
 self.datePicker = datePicker;
}
 
#pragma mark - UITextFieldDelegate
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
 if (_datePicker.frame.origin.y != mainH && _datePicker != nil) {
 [_datePicker dismiss];
 return NO;
 
 }else if (textField == _dateTextField) {
 [_datePicker show];
 return NO;
 }
 
 return YES;
}
 
#pragma mark - HWDatePickerDelegate
- (void)datePickerView:(HWDatePicker *)datePickerView didClickSureBtnWithSelectDate:(NSString *)date
{
 _dateTextField.text = date;
}
 
@end

HWDatePicker:

#import <UIKit/UIKit.h>
 
@class HWDatePicker;
 
@protocol HWDatePickerDelegate <NSObject>
 
/**
 * HWDatePicker確定按鈕點(diǎn)擊代理事件
 *
 * @param datePickerView HWDatePicker
 * @param date  選中的日期
 */
- (void)datePickerView:(HWDatePicker *)datePickerView didClickSureBtnWithSelectDate:(NSString *)date;
 
@end
 
@interface HWDatePicker : UIView
 
@property (nonatomic, weak) id<HWDatePickerDelegate> delegate;
 
- (void)show;
- (void)dismiss;
 
@end
 
 
#import "HWDatePicker.h"
 
//獲得屏幕的寬高
#define mainW [UIScreen mainScreen].bounds.size.width
#define mainH [UIScreen mainScreen].bounds.size.height
 
@interface HWDatePicker ()
 
@property (nonatomic, strong) UIDatePicker *datePicker;
 
@end
 
@implementation HWDatePicker
 
- (id)initWithFrame:(CGRect)frame
{
 if (self = [super initWithFrame:frame]) {
 //背景框
 UIImageView *back = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height)];
 back.image = [UIImage imageNamed:@"datePickerBj"];
 [self addSubview:back];
 
 //日期選擇器
 _datePicker = [[UIDatePicker alloc] init];
 _datePicker.frame = CGRectMake(10, 10, self.frame.size.width - 20, 120);
 _datePicker.backgroundColor = [UIColor clearColor];
 [_datePicker setDatePickerMode:UIDatePickerModeDate];
 NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"];
 _datePicker.locale = locale;
 NSDateFormatter *formatter_minDate = [[NSDateFormatter alloc] init];
 [formatter_minDate setDateFormat:@"yyyy-MM-dd"];
 NSDate *minDate = [formatter_minDate dateFromString:@"2008-01-01"];
 formatter_minDate = nil;
 [_datePicker setMinimumDate:minDate];
 [self addSubview:_datePicker];
 
 //確定按鈕
 UIButton *sureBtn = [[UIButton alloc] initWithFrame:CGRectMake((self.frame.size.width - mainW * 0.36) * 0.5, self.frame.size.height * 0.747, mainW * 0.36, mainW * 0.11)];
 [sureBtn setImage:[UIImage imageNamed:@"sureBtn"] forState:UIControlStateNormal];
 [sureBtn addTarget:self action:@selector(sureBtnOnClick) forControlEvents:UIControlEventTouchUpInside];
 [self addSubview:sureBtn];
 }
 
 return self;
}
 
- (void)sureBtnOnClick
{
 [self dismiss];
 
 if (_delegate && [_delegate respondsToSelector:@selector(datePickerView:didClickSureBtnWithSelectDate:)]) {
 [_delegate datePickerView:self didClickSureBtnWithSelectDate:[self getDateString]];
 }
}
 
- (NSString *)getDateString
{
 NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
 [dateFormatter setDateFormat:@"yyyy-MM-dd"];
 NSString *date = [dateFormatter stringFromDate:[self.datePicker date]];
 
 return date;
}
 
- (void)show
{
 [UIView animateWithDuration:0.3 animations:^{
 self.frame = CGRectMake(mainW * 0.05, mainH - mainW * 0.75, mainW * 0.9, mainW * 0.5);
 }];
}
 
- (void)dismiss
{
 [UIView animateWithDuration:0.3 animations:^{
 self.frame = CGRectMake(mainW * 0.05, mainH, mainW * 0.9, mainW * 0.5);
 }];
}
 
@end

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 用iOS模擬器安裝App的方法

    用iOS模擬器安裝App的方法

    下面小編就為大家分享一篇用iOS模擬器安裝App的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2018-01-01
  • IOS安裝CocoaPods詳細(xì)教程

    IOS安裝CocoaPods詳細(xì)教程

    這篇文章主要為大家詳細(xì)介紹了IOS安裝CocoaPods教程,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-05-05
  • 詳談iOS 位置權(quán)限彈出框閃現(xiàn)的問題

    詳談iOS 位置權(quán)限彈出框閃現(xiàn)的問題

    下面小編就為大家?guī)硪黄斦刬OS 位置權(quán)限彈出框閃現(xiàn)的問題。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-04-04
  • iOS App之間的通信 local socket

    iOS App之間的通信 local socket

    這篇文章主要介紹了iOS App之間的通信 local socket的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-09-09
  • Xcode中Info.plist字段詳解

    Xcode中Info.plist字段詳解

    我們通過本篇文章給大家整理了Xcode中Info.plist字段的詳細(xì)內(nèi)容,有需要的朋友學(xué)習(xí)下。
    2018-01-01
  • iOS中Sqlite和FMDB使用詳解

    iOS中Sqlite和FMDB使用詳解

    這篇文章主要為大家介紹了iOS中Sqlite和FMDB使用方法詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-10-10
  • IOS開發(fā)筆記整理49之詳解定位CLLocation

    IOS開發(fā)筆記整理49之詳解定位CLLocation

    在項(xiàng)目功能中有一個(gè)定位CLLocation的需求,遇到了一些知識(shí)難點(diǎn),經(jīng)過各位大俠的幫助,問題解決,特此分享供大家學(xué)習(xí),希望大家共同學(xué)習(xí)進(jìn)步
    2015-11-11
  • 詳解iOS開發(fā)中使用storyboard創(chuàng)建導(dǎo)航控制器的方法

    詳解iOS開發(fā)中使用storyboard創(chuàng)建導(dǎo)航控制器的方法

    這篇文章主要介紹了iOS開發(fā)中使用storyboard創(chuàng)建導(dǎo)航控制器的方法,包括對(duì)控制器聲明周期的控制介紹,代碼基于傳統(tǒng)的Objective-C,需要的朋友可以參考下
    2016-01-01
  • 實(shí)例講解iOS應(yīng)用UI開發(fā)之基礎(chǔ)動(dòng)畫的創(chuàng)建

    實(shí)例講解iOS應(yīng)用UI開發(fā)之基礎(chǔ)動(dòng)畫的創(chuàng)建

    這篇文章主要介紹了iOS應(yīng)用UI開發(fā)之基礎(chǔ)動(dòng)畫的創(chuàng)建,以關(guān)鍵幀動(dòng)畫作為重要知識(shí)點(diǎn)進(jìn)行講解,需要的朋友可以參考下
    2015-11-11
  • IOS倒計(jì)時(shí)設(shè)置UIButton標(biāo)題title的抖動(dòng)問題

    IOS倒計(jì)時(shí)設(shè)置UIButton標(biāo)題title的抖動(dòng)問題

    這篇文章主要介紹了IOS倒計(jì)時(shí)設(shè)置UIButton標(biāo)題title的抖動(dòng)問題,在發(fā)送驗(yàn)證碼后,button狀態(tài)需要變?yōu)閐isable,每隔一秒顯示倒計(jì)時(shí)時(shí)間,下面通過本文給大家介紹設(shè)置方法,一起看看吧
    2016-12-12

最新評(píng)論

宝清县| 金堂县| 泾源县| 桂平市| 鹿邑县| 宁化县| 如东县| 乌拉特中旗| 两当县| 治多县| 德令哈市| 淮阳县| 永年县| 五原县| 若尔盖县| 板桥市| 甘德县| 吴堡县| 景洪市| 大安市| 天柱县| 牟定县| 鄂托克旗| 讷河市| 镇巴县| 上栗县| 称多县| 汪清县| 哈尔滨市| 石棉县| 江华| 湘乡市| 海口市| 崇礼县| 柘城县| 东兴市| 新龙县| 涪陵区| 盐边县| 吉首市| 陆河县|