zoukankan      html  css  js  c++  java
  • XCODE UITextField 中的属性和用法

     

    XCODE  UITextField  中的属性和用法 一些基本的用法

    UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];

        CGRect frame =CGRectMake(110, 100, 100, 30);

        button.frame = frame;

        button.backgroundColor = [UIColor purpleColor];

        [button setTitle:@"command" forState:UIControlStateNormal];

        [button setTitleColor:[UIColor yellowColor ] forState:UIControlStateNormal];

        button.layer.cornerRadius = 10.0;

        [button addTarget:self action:@selector(test) forControlEvents:UIControlEventTouchUpInside];

        [self.window addSubview: button];

        UITextField *tf = [[UITextField alloc]initWithFrame:CGRectMake(110, 150, 100, 30)];

        tf.tag = 101;

        tf.borderStyle =UITextBorderStyleRoundedRect ;

        //UITextBorderStyleLine 输入框框边为黑色的边款,白色背景

        //UITextBorderStyleBezel  输入框的边款为灰色,白色背景

        //UITextBorderStyleRoundedRect 输入框为圆角,白色背景的输入框

    //    tf.text =@"abc" ;

         tf.textColor = [UIColor purpleColor];

        tf.textAlignment = NSTextAlignmentCenter;//输入的内容显示在方框的中心

        //提示用户输入什么内容

        tf.placeholder =@"用来提示用户";

        //与密码输入时一样,输入后显现为黑色的圆点

    //    tf.secureTextEntry = YES;

        //根据输入内容自动调节字体的大小

        tf.adjustsFontSizeToFitWidth = YES;

      //对用键盘输入内容进行限制和切换

        //keyboardType 以下是常用的类型,其他的看单词就知道键盘的类型

        //UIKeyboardTypeDecimalPad,UIKeyboardTypeNumberPad 输入框限制为输入数字,且前一个多可以输入小数点

        //UIKeyboardTypeNumbersAndPunctuation 键盘为数字加标点符号

        //UIKeyboardTypeDefault  为默认(常规)的键盘

        tf.keyboardType = UIKeyboardTypeDefault;

        //returnKeyType  键盘 显示返回(完成)时执行的操作 提示按钮 以下是常用的几种

        //UIReturnKeyEmergencyCall  键盘的右下角 有一个 EmergencyCall 的(紧急呼叫)功能按钮

        //UIReturnKeyGoogle 键盘的右下角 有一个 Search (功能提示按钮)

        tf.returnKeyType = UIReturnKeyDefault;

        //Bool  输入时清空 输入框的内容

    //    tf.clearsOnBeginEditing = YES;

        //clearButtonMode  输入款清除(一个叉的符号)按钮出显示的时间

    //    tf.clearButtonMode = UITextFieldViewModeAlways;

        //设置代理

    //    tf.delegate = self;

        //自定义设置左视图

    //    UIView *leftLabel = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 20, 20)];

    //    leftLabel.backgroundColor = [UIColor yellowColor];

    //    tf.rightView = leftLabel;

    //    [leftLabel release];

    //   tf.rightViewMode = UITextFieldViewModeWhileEditing;

        //自定定义键盘

    //    UIView *leftLabel1 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 20, 20)];

    //    leftLabel1.backgroundColor = [UIColor yellowColor];

    //    tf.inputView= leftLabel1;

    //    [leftLabel1 release];

        //设置键盘上公用的区域

        UIView *leftLabel2 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 20)];

        leftLabel2.backgroundColor = [UIColor yellowColor];

        tf.inputAccessoryView= leftLabel2;

        [leftLabel2 release];

     

       

        //autocapitalizationType  设置对输入的字母大小写的设置

        //UITextAutocapitalizationTypeWords 设置每个单词的首字母为大写

        //UITextAutocapitalizationTypeSentences 设置一个句子中的首个单词的字母为大写

        //UITextAutocapitalizationTypeAllCharacters  每个字母都大写 7.0)以上的最后一个字母大写

        //UITextAutocapitalizationTypeNone  不切换大小写

        tf.autocapitalizationType = UITextAutocapitalizationTypeNone;

        

        

        

     

        [self.window addSubview:tf];//2

        [tf release];

        

        [self.window makeKeyAndVisible];

        return YES;

    }

    -(void)test

    {

        UITextField  *tf =(UITextField *) [self.window viewWithTag:101];

        //将键盘移除

        [tf resignFirstResponder];

    }

  • 相关阅读:
    零基础转IT,我推荐你学习这三门技术
    蜗牛学院行内人分析:参加IT培训,大家一定要注意这五点!
    蜗牛学院分析:Web前端开发的就业前景怎么样,薪资待遇如何?
    软件测试和测试开发有什么区别?
    转行者越来越多,程序员是不是不值钱了呢?
    蜗牛学院卿老师:Python中几个比较容易混淆的概念解释
    webpack4.x的css单独打包、合并、自动添加前缀、压缩
    webpack4的splitChunksPlugin配置参数详解---代码分割 、懒加载以及prefetching 和 preloading
    vue列表页进入详情页,返回列表项不刷新
    js数组去重
  • 原文地址:https://www.cnblogs.com/meixian/p/4536750.html
Copyright © 2011-2022 走看看