• iOS开发UI篇—Date Picker和UITool Bar控件简单介绍


    iOS开发UI—Date PickerUITool Bar控件简单介绍

    一、Date Picker控件

    1.简单介绍:

    Date Picker显示时间的控件

    有默认宽高,不用设置数据源和代理

    如何改成中文的?

    (1)查看当前系统是否为中文的,把模拟器改成是中文的

    (2)属性,locale选择地区

    如果默认显示不符合需求。时间有四种模式可以设置,在model中进行设置

    时间可以自定义(custom)。

    设置最小时间和最大时间,超过就会自动回到最小时间。

    最大的用途在于自定义键盘:弹出一个日期选择器出来,示例代码如下:

     2.示例代码

      1 #import "TXViewController.h"
      2 
      3  
      4 
      5 @interface TXViewController ()
      6 
      7 /**
      8 
      9  *  文本输入框
     10 
     11  */
     12 
     13 @property (weak, nonatomic) IBOutlet UITextField *textfired;
     14 
     15  
     16 
     17 @end
     18 
     19  
     20 
     21 @implementation TXViewController
     22 
     23  
     24 
     25 - (void)viewDidLoad
     26 
     27 {
     28 
     29     [super viewDidLoad];
     30 
     31 //添加一个时间选择器
     32 
     33     UIDatePicker *data = [[UIDatePicker alloc]init];
     34 
     35     
     36 
     37     //设置只显示中文
     38 
     39     
     40 
     41     [data setLocale:[NSLocale localeWithLocaleIdentifier:@"zh-CN"]];
     42 
     43     //只显示日期
     44 
     45     data.datePickerMode = UIDatePickerModeDate;
     46 
     47     
     48 
     49     
     50 
     51     //当光标移动到文本框时,召唤时间选择器
     52 
     53     
     54 
     55     self.textfired.inputView = data;
     56 
     57     
     58 
     59     //2创建工具条
     60 
     61     UIToolbar *toolbar = [[UIToolbar alloc]init];
     62 
     63     
     64 
     65     //设置工具条的颜色
     66 
     67     
     68 
     69     toolbar.barTintColor = [UIColor redColor];
     70 
     71     
     72 
     73     //设置工具条的颜色
     74 
     75     toolbar.frame = CGRectMake(0, 0, 320, 55);
     76 
     77     
     78 
     79     //给工具条添加按钮
     80 
     81     
     82 
     83     UIBarButtonItem *item0=[[UIBarButtonItem alloc]initWithTitle:@"上一个"style:UIBarButtonItemStylePlaintarget:self action:@selector(didClick) ];
     84 
     85     UIBarButtonItem *item1=[[UIBarButtonItem alloc]initWithTitle:@"下一个"style:UIBarButtonItemStylePlaintarget:self action:@selector(didClick) ];
     86 
     87     //弹簧
     88 
     89     UIBarButtonItem *item2=[[UIBarButtonItemalloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpacetarget:nil action:nil];
     90 
     91     UIBarButtonItem *item3=[[UIBarButtonItem alloc]initWithTitle:@"完成"style:UIBarButtonItemStylePlain target:self action:@selector(didClick)];
     92 
     93     toolbar.items = @[item0,item1,item2,item3];
     94 
     95     
     96 
     97     //设置文本输入框键盘的辅助视图
     98 
     99          self.textfired.inputAccessoryView=toolbar;
    100 
    101 }
    102 
    103 -(void)didClick
    104 
    105 {
    106 
    107     NSLog(@"fjlsd");
    108 
    109     
    110 
    111 }
    112 
    113 - (void)didReceiveMemoryWarning
    114 
    115 {
    116 
    117     [super didReceiveMemoryWarning];
    118 
    119     // Dispose of any resources that can berecreated.
    120 
    121 }
    122 
    123  
    124 
    125 @end

    实现效果:

    二、UITool Bar

    在上面可以添加子控件TOOLBAR中只能添加UIBarButtonItem子控件,其他子控件会被包装秤这种类型的

    上面的控件依次排放(空格————)

    有样式,可以指定样式(可拉伸的),一般用来做工具栏。

    使用toolbar做点菜的头部标题

    如何让点菜系统居中?在ios6中是正的,在ios7中是歪的

    在自定义键盘上加上一个工具栏。

    数组里什么顺序放的,就按照什么顺序显示

      toolbar.items = @[item0,item1, item2, item3];
        //设置文本输入框键盘的辅助视图
       self.textfield.inputAccessoryView=toolbar;

  • 相关阅读:
    arcgis 线转面
    CAD 命令
    一台服务器挂多个网站
    请教:gridview
    转折
    网站开发标准
    [导入]简单网站开发
    过年了!
    web.config的问题
    java 计算程序执行时间
  • 原文地址:https://www.cnblogs.com/asd5551680/p/4069716.html
Copyright © 2020-2023  润新知