zoukankan      html  css  js  c++  java
  • IOS UI-键盘处理和UIToolbar

     1 //
     2 //  ViewController.m
     3 //  IOS_0225-键盘处理和UIToolBar
     4 //
     5 //  Created by ma c on 16/2/25.
     6 //  Copyright © 2016年 博文科技. All rights reserved.
     7 //
     8 
     9 #import "ViewController.h"
    10 
    11 @interface ViewController ()
    12 
    13 @property (nonatomic, strong) UITextField *textField;
    14 
    15 @end
    16 
    17 @implementation ViewController
    18 
    19 - (void)viewDidLoad {
    20     [super viewDidLoad];
    21     self.view.backgroundColor = [UIColor cyanColor];
    22 
    23     [self createTextField];
    24 }
    25 
    26 - (void)createTextField
    27 {
    28     self.textField = [[UITextField alloc] initWithFrame:CGRectMake(100, 100, 214, 44.0)];
    29     self.textField.borderStyle = UITextBorderStyleRoundedRect;
    30     self.textField.placeholder = @"请输入内容";
    31     self.textField.clearButtonMode = UITextFieldViewModeAlways;
    32     [self.view addSubview:self.textField];
    33     
    34     //自定义文本框的键盘
    35     self.textField.inputView = [UIButton buttonWithType:UIButtonTypeContactAdd];
    36     //自定义文本框上面的辅助工具控件
    37     UIToolbar *toolBar = [[UIToolbar alloc] init];
    38     [toolBar sizeToFit];
    39     toolBar.barTintColor = [UIColor redColor];
    40     
    41     UIBarButtonItem *item1 = [[UIBarButtonItem alloc] initWithTitle:@"上一个" style:UIBarButtonItemStylePlain target:self action:@selector(previewClick)];
    42     UIBarButtonItem *item2 = [[UIBarButtonItem alloc] initWithTitle:@"下一个" style:UIBarButtonItemStylePlain target:self action:@selector(nextClick)];
    43     UIBarButtonItem *item3 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
    44     UIBarButtonItem *item4 = [[UIBarButtonItem alloc] initWithTitle:@"完成" style:UIBarButtonItemStylePlain target:self action:@selector(doneClick)];
    45     toolBar.items = @[item1,item2,item3,item4];
    46     self.textField.inputAccessoryView = toolBar;
    47     
    48 }
    49 
    50 - (void)previewClick
    51 {
    52     NSLog(@"上一个");
    53 }
    54 
    55 - (void)nextClick
    56 {
    57     NSLog(@"下一个");
    58 }
    59 
    60 - (void)doneClick
    61 {
    62     [self.view endEditing:YES];
    63 }
    64 
    65 @end
  • 相关阅读:
    pthread_create用法
    linux下C和shell调用的popen函数
    Linux下使用popen()执行shell命令
    RBL, UBL, Uboot的关系
    windows下搭建NFS服务器
    windows nfs server for linux
    PowerDesigner数据模型(CDM—PDM—SQL脚本的转换流程)
    PowerDesigner反向生成数据库模型(MySql篇)
    JAVA Apache POI 之sax 解析10万级大数量数据
    GC overhead limit exceeded,tomcat修改jvm内存
  • 原文地址:https://www.cnblogs.com/oc-bowen/p/5218186.html
Copyright © 2011-2022 走看看