美文网首页
UIDatePicker和UIToolBar

UIDatePicker和UIToolBar

作者: 石玉龙 | 来源:发表于2016-11-05 19:43 被阅读31次

    DatePicker显示时间的控件:有默认宽度,不用设置数据源和代理;

    如何改成中文的?

    1> 查看当前系统是否为中文,把模拟器改成中文;

    2> 属性,locale选择地区;

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

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

    最大的用途在于自定义键盘:弹出一个日期选择器出来;

    UIDatePicker *picker = [[UIDatePicker alloc] init];

    [picker setLocale:[NSLocale localeWithLocaleIdentifier:@"zh-CN"]];

    picker.datePickerMode = UIDatePickerModeDate;

    _viewfield = [[UITextField alloc] initWithFrame:CGRectMake(20, button.frame.origin.y + 30 +10, [UIScreen mainScreen].bounds.size.width-40, 40)];

    _viewfield.keyboardType = UIKeyboardTypeDefault;

    _viewfield.placeholder = @"请输入密码";

    _viewfield.leftViewMode = UITextFieldViewModeAlways;

    _viewfield.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;

    _viewfield.textColor = [UIColor darkTextColor];

    _viewfield.font = [UIFont fontWithName:@"Arial" size:20.0];

    _viewfield.clearButtonMode = UITextFieldViewModeAlways;

    _viewfield.borderStyle = UITextBorderStyleRoundedRect;

    _viewfield.secureTextEntry = YES;

    _viewfield.returnKeyType = UIReturnKeyDone;

    _viewfield.delegate = self;

    [self.view addSubview:_viewfield];

    _viewfield.inputView = picker;

    UIToolbar *tool = [[UIToolbar alloc] init];

    tool.barTintColor = [UIColor brownColor];

    tool.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 44);

    UIBarButtonItem *item1 = [[UIBarButtonItem alloc] initWithTitle:@"上一个" style:UIBarButtonItemStylePlain target:self action:@selector(itemClick:)];

    UIBarButtonItem *item2 = [[UIBarButtonItem alloc] initWithTitle:@"下一个" style:UIBarButtonItemStylePlain target:self action:@selector(itemClick:)];

    UIBarButtonItem *space = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];

    UIBarButtonItem *item3 = [[UIBarButtonItem alloc] initWithTitle:@"完成" style:UIBarButtonItemStylePlain target:self action:@selector(itemClick:)];

    tool.items = @[item1, item2, space, item3];

    _viewfield.inputAccessoryView = tool;

    相关文章

      网友评论

          本文标题:UIDatePicker和UIToolBar

          本文链接:https://www.haomeiwen.com/subject/dmlguttx.html