zoukankan      html  css  js  c++  java
  • UITextfield设置Placeholder颜色 控件 内边距、自适应高度

    //创建UITextField对象
    UITextField * tf=[[UITextField alloc]init];
     
     //设置Placeholder颜色

     [text setAttributedPlaceholder:[[NSAttributedString alloc]initWithString:CustomLocalizedString(@"UserName", nil) attributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}]];

    //设置UITextField的文字颜色
    tf.textColor=[UIColor redColor];
     
    //设置UITextField的文本框背景颜色
    tf.backgroundColor=[UIColor grayColor];
     
    //设置UITextField的边框的风格
    tf.borderStyle=UITextBorderStyleRoundedRect;
     
    //设置UITextField的代理
    tf.delegate=self;
     
    //设置UITextField的文字对齐方式
    tf.textAlignment=UITextAlignmentCenter;//居中对齐
    tf.textAlignment=UITextAlignmentLeft;//左对齐
    tf.textAlignment=UITextAlignmentRight;//右对齐
    tf.textAlignment=UITextAlignmentFill;//填充对齐
     
    //设置UITextField的文字大小和字体
    tf.font=[UIFont fontWithName:@"Times New Roman" size:20];
     
    //设置左边距

     {

                CGRect frame = [text frame];

                frame.size.width=8.0f;

                [text setLeftView:[[UIView alloc]initWithFrame:frame]];

                [text setLeftViewMode:UITextFieldViewModeAlways];

            }

     
     
    //设置UITextField自适应文本框大小
    tf.adjustsFontSizeToFitWidth=YES/NO;//自适应宽度
    tf.adjustsFontSizeToFitHeight=YES/NO;//自适应高度
     
    //设置UITextField是否拥有一键清除的功能
    tf.clearsOnBeginEditing=YES/NO;
     
    //设置一键清除按钮是否出现
    tf.clearButtonMode=UITextFieldViewModeNever;
     
    //设置UITextField的初始隐藏文字
    tf.placeholder=@"输入密码";
     
    //当UITextField的样式为UITextBorderStyleNone的时候,修改背景图片
    tf.background=[UIImage imageNamed:@"xx.png"];
     
    //设置UITextField的左边view
    tf.leftView=xxx;
     
    //设置UITextField的左边view出现模式
    tf.leftViewMode=UITextFieldViewModeAlways;
     
    //设置UITextField的右边view
    tf.rightView=xxx;
     
    //设置UITextField的右边view出现模式
    tf.rightViewMode=UITextFieldViewModeAlways;
     
    //设置UITextField的字的摆设方式
    tf.contentVerticalAlignment=UIControlContentVerticalAlignmentCenter;
  • 相关阅读:
    使用灰层覆盖UI时,有事发生
    通过自定义ISAPI Filter来禁止敏感文件的访问
    静态链接库LIB和动态链接库DLL的区别 创建和示例
    深入剖析C++中的string类
    .net c# 序列化和反序列
    ASP.NET 状态服务 及 session丢失问题解决方案总结
    IWAM_账号的用途以及如何同步密码
    COM 组件设计与应用(一)起源及复合文件
    两种古老的WEB编程技术 CGI和ISAPI之间的区别
    Send MSMQ Messages Securely Across the Internet with HTTP and SOAP
  • 原文地址:https://www.cnblogs.com/niit-soft-518/p/4680112.html
Copyright © 2011-2022 走看看