zoukankan      html  css  js  c++  java
  • datepicker自定义 -- iOS

    /**
     *  创建时间选择器
     */
    - (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(0, 0, SCREEN_WIDTH, 30); // 给工具条添加按钮 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 - 100; 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:10]; self.birthTextField.text = birth; [_birthTextField resignFirstResponder]; }

     效果如下:

  • 相关阅读:
    Ural_1018. Binary Apple Tree(树形DP)
    2011 Asia Shanghai Regional Contest Problem A
    Ural_1012. Kbased Numbers. Version 2(dp)
    HDU_1524 A Chess Game (sg函数)
    HDU_1760 A New Tetris Game(dfs + 博弈)
    POJ_2023 Choose Your Own Adventure(DFS)
    POJ_3267 The Cow Lexicon(DP)
    Qt 的QString类的使用
    用QFileSystemModel和Listview做的简易图片浏览
    Qt 对文件的操作
  • 原文地址:https://www.cnblogs.com/mafeng/p/5832801.html
Copyright © 2011-2022 走看看