• UITextField的详细使用


    //用来显示“用户名”的label

    //初始化textfield并设置位置及大小

    UILabel* label1 = [[UILabelallocinitWithFrame:CGRectMake(15657030)];

        label1.backgroundColor = [UIColorclearColor];

        label1.font = [UIFontfontWithName:@"Helvetica-Bold"size:18];

        label1.text = @"用户名";

        label1.textColor = [UIColorwhiteColor];

        [view1 addSubview:label1];

        [label1 release];

       UITextField * accountField = [[UITextField allocinitWithFrame:CGRectMake(85.0f60.0f190.0f40.0f)];

    [accountField setBorderStyle:UITextBorderStyleRoundedRect]; //外框类型

    accountField.placeholder = @"用户名"; //默认显示的字

    accountField.secureTextEntry = NO; //是否以密码形式显示

    accountField.autocorrectionType = UITextAutocorrectionTypeNo;//设置是否启动自动提醒更正功能

    accountField.autocapitalizationType = UITextAutocapitalizationTypeNone;

    accountField.returnKeyType = UIReturnKeyDone;  //键盘返回类型

    accountField.clearButtonMode = UITextFieldViewModeWhileEditing//编辑时会出现个修改X

    accountField.delegate = self;

    accountField.keyboardType = UIKeyboardTypeDefault;//键盘显示类型

    accountField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter//设置居中输入

    accountField.scrollEnabled = YES;//是否可以拖动

    accountField.autoresizingMask = UIViewAutoresizingFlexibleHeight;//自适应高度

     //用来显示“密码”的label

        UILabel* label2 = [[UILabelallocinitWithFrame:CGRectMake(151207030)];

        label2.backgroundColor = [UIColorclearColor];

        label2.font = [UIFontfontWithName:@"Helvetica-Bold"size:18];

        label2.text = @"密码";

        label2.textColor = [UIColorwhiteColor];

        [view1 addSubview:label2];

        [label2 release];

      UITextField*  passwdField = [[UITextField allocinitWithFrame:CGRectMake(85.0f115.0f190.0f40.0f)];

    //设置边框样式,只有设置了才会显示边框样式

    [passwdFieldsetBorderStyle:UITextBorderStyleRoundedRect]; //外框类型

    //passwdField.placeholder = @"密码"; //默认显示的字

    passwdField.secureTextEntry = YES//密码类型

    passwdField.autocorrectionType = UITextAutocorrectionTypeNo;   

    passwdField.autocapitalizationType = UITextAutocapitalizationTypeNone;

    passwdField.returnKeyType = UIReturnKeyDone;

    passwdField.clearButtonMode = UITextFieldViewModeWhileEditing//编辑时会出现个修改X //输入框中是否有个叉号,在什么时候显示,用于一次性删除输入框中的内容

    //设置代理 用于实现协议

    passwdField.delegate = self;

     // passwdField.keyboardAppearance = UIKeyboardAppearanceDefault;

    passwdField.keyboardType = UIKeyboardTypeNumbersAndPunctuation;

    passwdField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;

    委托方法

    -(void)textFieldDidBeginEditing:(UITextField *)textField;  

    //当开始点击textField会调用的方法    

    -(void)textFieldDidEndEditing:(UITextField *)textField; 

    //当textField编辑结束时调用的方法

    //按下Done按钮的调用方法,我们让键盘消失   

    -(BOOL)textFieldShouldReturn:(UITextField *)textField{  

     [textField resignFirstResponder];  

     return YES;

  • 相关阅读:
    架构师养成记--34.Redis持久化
    架构师养成记--33.Redis哨兵、redis简单事务
    js获取当前项目根路径URL (转自CSDN 红领巾-sunlight)
    架构师养成记--32.Redis高级(安全 主从复制)
    架构师养成记--31.Redis的几种类型
    架构师养成记--30.Redis环境搭建
    oracle split(转自--博客园 linbo.yang)
    架构师养成记--29.redis开篇
    129、Java面向对象之static关键字一(修改static变量)
    128、Java面向对象之对象的比较
  • 原文地址:https://www.cnblogs.com/flower42/p/3307073.html
Copyright © 2020-2023  润新知