zoukankan      html  css  js  c++  java
  • UITextField

    UITextField是控制⽂字的输⼊和显⽰的控件。      
    所谓输⼊,在iOS⾥就是,点击输⼊框的时候,会弹出键盘,并能把键盘收回。
    相⽐于UILabel,UITextField不仅能显⽰⽂字,更能输⼊⽂字。      
    创建UITextField遵循以下⼏个步骤:  
    1、alloc开辟空间,initWithFrame初始化与屏幕的⼤⼩。    
    2、设置UITextField的相关属性; 
    3、把UITextField添加到⽗视图,得以显⽰出来; 
    UITextField继承于UIControl,后者继承于UIview。所以,UITextField对象拥有
    UIView和UIControl的所有⽅法和属性。
    //
    //  ViewController.m
    //  UITextField01
    //
    //  Created by cqy on 16/2/13.
    //  Copyright © 2016年 程清杨. All rights reserved.
    //

    #import "ViewController.h"

    @interface ViewController ()<UITextFieldDelegate>{
        UITextField *field;
        UIView *view;
    }

    @end

    @implementation ViewController

    - (void)viewDidLoad {
        [super viewDidLoad];
        view = [[UIView alloc]initWithFrame:CGRectMake(10, 0, 30, 60)];
        view.backgroundColor = [UIColor yellowColor];
        field = [[UITextField alloc]initWithFrame:CGRectMake(20, 20, 200, 50)];
        field.delegate = self;
        //属性
        //borderStyle:输⼊框的边框样式,是⼀个枚举值。
        field.borderStyle = UITextBorderStyleRoundedRect;
       
        //text:属性text表⽰要显⽰的内容
        //field.text = @"Hellow world !";//此时,在输⼊框中,有Hellow world !字样。这个text会获取输⼊框所有的⽂字。
        //textColor:要显⽰的⽂本的颜⾊
        field.textColor = [UIColor redColor];
        //textAlignment:输⼊框⽂本的对齐⽅式(⽔平⽅向),默认左对齐
        field.textAlignment = NSTextAlignmentLeft;
        //fond:输⼊框中,字体的样式和⼤⼩
        field.font = [UIFont fontWithName:@"Helvetica-Bold" size:20];
        field.font = [UIFont systemFontOfSize:20];
        //placholder:在输⼊框中没有⽂字时,placeholder提供了占位符,⽤以提⽰
        field.placeholder = @"请输入!";
        //enabled:是否允许输⼊框输⼊东西。返回值是BOOl类型。默认是YES,允许输⼊。
        field.enabled = YES;
        //clearsOnBeginEditing:是否开始输⼊的时候,清空输⼊框的⽂字内容。返回值是BOOL类型的。默认值是NO不清空。
        field.clearsOnBeginEditing = YES;
        //clearButtonMode:是否显示清空按钮
        field.clearButtonMode = YES;
        //secureTextEntry:是否输⼊的⽂字⽤圆点来代替显⽰(密码形式,默认NO)
        field.secureTextEntry = YES;
        //keyboardType:控制点击输⼊框时,弹出来的键盘是什么类型的键盘(枚举值)。
        field.keyboardType = UIKeyboardTypeDefault;
        //returnKeyType:弹出来的键盘最右下⾓的return键的类型。
        field.returnKeyType = UIReturnKeySearch;
      
        //inputView:定义输⼊视图(默认是键盘)。也就是说,在点击输⼊框的时候,⾃定义弹出来⼀个能输⼊的视图(键盘就是。
       // field.inputView = view;
        //inputAccessoryView:在弹出键盘的上⽅,⼀起弹出⼀个辅助视图,由我们⾃⼰定义辅助视图实现的功能。(默认是nil,也就是弹出来的视图上什么都没有)
        //leftView:方框左视图leftView要与leftViewMode配套使⽤才能⽣效(对应rightView)。
        field.leftViewMode = UITextFieldViewModeAlways;
        field.leftView = view;
        [self.view addSubview:field];
       
            // Do any additional setup after loading the view, typically from a nib.
    }
    //点击return键触发事件
    -(BOOL)textFieldShouldReturn:(UITextField *)textField{
        [field resignFirstResponder];//解除第⼀响应者,把键盘回收。
        return YES;
    }

    - (void)didReceiveMemoryWarning {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    @end
  • 相关阅读:
    text-overflow:ellipsis; 使用
    js jquery jquery.wordexport.js 实现导出word
    CI框架程序--本地调试之后部署新浪SAE
    跳转页面的几种方式[归纳整理中......]
    使用jquery插件报错:TypeError:$.browser is undefined的解决方法
    apache Internal Server Error 的几个问题
    【总结整理】用户的需求分析:问对问题才能找准用户需求----摘自《人人都是产品经理》
    【总结整理】如何成为小白用户----摘自《人人都是产品经理》
    【总结整理双十一促销门道---摘自《人人都是产品经理》
    【总结整理】2018淘宝双11评价
  • 原文地址:https://www.cnblogs.com/iQingYang/p/5193184.html
Copyright © 2011-2022 走看看