/**
* 创建时间选择器
*/
- (void)createPickerView {
self.datePicker = [[UIDatePicker alloc] init];
_datePicker.backgroundColor = [UIColor whiteColor];
// 设置只显示中文
[_datePicker setLocale:[NSLocale localeWithLocaleIdentifier:@"zh-CN"]];
// 设置只显示日期
_datePicker.datePickerMode = UIDatePickerModeDate;
// 当光标移动到文本框时, 召出时间选择器
self.birthTextField.inputView = _datePicker;
// 创建工具条
UIToolbar *toolBar = [[UIToolbar alloc] init];
// 设置背景色
toolBar.barTintColor = [UIColor whiteColor];
toolBar.frame = CGRectMake(, , SCREEN_WIDTH, );
// 给工具条添加按钮
UIBarButtonItem *cancleItem = [[UIBarButtonItem alloc] initWithTitle:@"取消" style:UIBarButtonItemStylePlain target:self action:@selector(cancel)];
UIBarButtonItem *spaceItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:self action:nil];
// 设置UIBarButtonSystemItemFixedSpace的宽度
spaceItem.width = SCREEN_WIDTH - ;
UIBarButtonItem *sureItem = [[UIBarButtonItem alloc] initWithTitle:@"确认" style:UIBarButtonItemStylePlain target:self action:@selector(sure)];
// 设置字体颜色
toolBar.tintColor = [UIColor redColor];
toolBar.items = @[cancleItem, spaceItem, sureItem];
// 设置文本输入框键盘的辅助视图
self.birthTextField.inputAccessoryView = toolBar;
}
/**
* 点击取消按钮
*
* @param datePicker
*/
- (void)cancel { }
/**
* 点击确定按钮
*
* @param datePicker
*/
- (void)sure {
NSString *date = [NSString stringWithFormat:@"%@", _datePicker.date];
NSString *birth = [date substringToIndex:];
self.birthTextField.text = birth;
[_birthTextField resignFirstResponder];
}

效果如下:

datepicker自定义 -- iOS的更多相关文章

  1. 自定义iOS 中推送消息 提示框

    看到标题你可能会觉得奇怪 推送消息提示框不是系统自己弹出来的吗? 为什么还要自己自定义呢? 因为项目需求是这样的:最近需要做 远程推送通知 和一个客服系统 包括店铺客服和官方客服两个模块 如果有新的消 ...

  2. 【转】自定义iOS的Back按钮(backBarButtonItem)和pop交互手势(interactivepopgesturerecognizer) --- 不错

    原文网址:http://blog.csdn.net/joonsheng/article/details/41362499 序 说到自定义UINavigetionController的返回按钮,iOS7 ...

  3. 如何自定义iOS中的控件

    本文译自 How to build a custom control in iOS .大家要是有什么问题,可以直接在 twitter 上联系原作者,当然也可以在最后的评论中回复我. 在开发过程中,有时 ...

  4. VCTransitionsLibrary –自定义iOS交互式转场动画的库

    简介 VCTransitionsLibrary 提供了许多适用于入栈,出栈,模态等场景下控制器切换时的转场动画.它本身提供了一个定义好的转场动画库,你可以拖到自己工程中直接使用;也提供了许多拥有不同转 ...

  5. 自定义iOS上双击Home键图切换

    如果双击Home,会来到iOS App的switcher页面,在这儿列出了当前系统挂起的App, 上面有每个App的切屏,相信大家都熟悉这个东东了.它其实是每个App在挂起前,对App后个载屏. 那么 ...

  6. UIview 学习与自定义--ios

    UIView *view1=[[UIView alloc] initWithFrame:CGRectMake(50, 50, 100, 100)]; view1.backgroundColor=[UI ...

  7. 对话框 自定义 IOS风格 包青天

    activity     private void showDialog1() {         message = "您输入的邮箱后缀不是公司邮箱地址\n将导致您的借款审核不通过,请重新 ...

  8. 自定义ios NSLog

    #ifdef DEBUG #define MyLog(FORMAT, ...) fprintf(stderr,"Time:%s\t File:%s\t Methods:%s\t Line:% ...

  9. 利用贝塞尔曲线绘制(UIBezierPath)自定义iOS动态速度表,可以自定义刻度,刻度值,进度条样式

    GitHub的Demo下载地址 使用UIBezierPath画图步骤: 创建一个UIBezierPath对象 调用-moveToPoint:设置初始线段的起点 添加线或者曲线去定义一个或者多个子路径 ...

随机推荐

  1. centos6.7 安装Docker

      一.查看系统版本 [root@localhost ~]# cat /etc/redhat-release CentOS release 6.7 (Final) 二.安装EPEL 1.进入cento ...

  2. Mongodb 主从复制与副本集实验

    1.实验主从复制,并验证复制成功,抓图实验过程  Step1:创建相应的目录 Mkdir -p ./dbs/master Mkdir -p ./dbs/slave Step2:开启主服务 ./bin/ ...

  3. POJ 3398 Perfect Service --最小支配集

    题目链接:http://poj.org/problem?id=3398 这题可以用两种上述讲的两种算法解:http://www.cnblogs.com/whatbeg/p/3776612.html 第 ...

  4. pedestal-工作记

    1.基于bootstrap-v3和flat-ui-v3为第十届外语活动月写了个页面 http://www.pedestal.cn/static/activity/index.html 2.资料 boo ...

  5. [Usaco2010 OPen]Triangle Counting 数三角形

    [Usaco2010 OPen]Triangle Counting 数三角形 Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 394  Solved: 1 ...

  6. 后台跳转到登录页嵌套在iframe的问题(MVC例)

    //首页 public ActionResult Index() { if (!Request.IsAuthenticated) //判断权限,没有登录就跳回登录页 {string url = Url ...

  7. 【转】【SSE】基于SSE指令集的程序设计简介

    基于SSE指令集的程序设计简介 作者:Alex Farber 出处:http://www.codeproject.com/cpp/sseintro.asp SSE技术简介 Intel公司的单指令多数据 ...

  8. 【C#】【MySQL】C# 查询数据库语句@Row:=@Row+1

    如何实现数据库查询产生虚拟的一列序号的功能: ) )AS r; 该语句可以实现产生虚拟的一列数据在MySQL中运行没有问题. 但是在C#里面调用去出现了错误"Parameter '@ROW' ...

  9. java中从1970-1-1到当前时间之间的毫秒数转换为oracle date

    java中System.currentTimeMillis()取到的是从1970-01-01 00:00:00.000到当前时间的毫秒数,一个long类型的值. 现在oracle数据库中某表中存取的是 ...

  10. Android tab导航的几种方法:ActionBar tab +fragment,Viewpager+pagerTitleStrip,开源框架ViewPageIndicator 和 ViewPager

    action来实现tab标签 并跟fragment结合 因为要写新闻客户端这个tab导航是必须的 这里我写几个小练习,希望大家融会贯通. 1actionbar设置tab +fragment 布局是个l ...