当前位置: 首页 > news >正文

iOS开发UITextField设置

// 设置边框样式

/* UITextBorderStyleNone, 无边框,默认 UITextBorderStyleLine, 直线边框 UITextBorderStyleBezel, 边框 + 阴影 UITextBorderStyleRoundedRect 圆角矩形边框 */ textField.borderStyle = UITextBorderStyleLine; // 设置背景颜色 /* 默认是透明的 */ textField.backgroundColor = [UIColor yellowColor]; // 设置背景图片 textField.background = [UIImage imageNamed:@"pic2"]; // 设置提示文字 /* 用户输入时自动消失 */ textField.placeholder = @"请输入用户名"; // 设置输入的字体颜色 textField.textColor = [UIColor redColor]; // 设置文字对齐方式 textField.textAlignment = NSTextAlignmentLeft; // 设置最小可缩小的字号 textField.minimumFontSize = 10; // 自动调整文字大小 /* 自动调整文字的大小以适应 textField 的宽度 */ textField.adjustsFontSizeToFitWidth = YES; // 设置密文输入模式 /* default is NO */ textField.secureTextEntry = YES; // 设置显示清除按钮 /* UITextFieldViewModeNever, // default UITextFieldViewModeWhileEditing, UITextFieldViewModeUnlessEditing, UITextFieldViewModeAlways */ textField.clearButtonMode = UITextFieldViewModeWhileEditing; // 设置键盘样式 /* UIKeyboardTypeDefault, // Default type for the current input method. UIKeyboardTypeASCIICapable, // Displays a keyboard which can enter ASCII characters, // non-ASCII keyboards remain active UIKeyboardTypeNumbersAndPunctuation, // Numbers and assorted punctuation. UIKeyboardTypeURL, // A type optimized for URL entry. UIKeyboardTypeNumberPad, // A number pad (0-9). Suitable for PIN entry. UIKeyboardTypePhonePad, // A phone pad (1-9, *, 0, #, with letters under the numbers). UIKeyboardTypeNamePhonePad, // A type optimized for entering a person's name or phone number. UIKeyboardTypeEmailAddress, // A type optimized for multiple email address entry. UIKeyboardTypeDecimalPad, // A number pad with a decimal point. UIKeyboardTypeTwitter, // A type optimized for twitter text entry (easy access to @ #) UIKeyboardTypeWebSearch, // A default keyboard type with URL-oriented addition. UIKeyboardTypeAlphabet = UIKeyboardTypeASCIICapable, // Deprecated */ textField.keyboardType = UIKeyboardTypeDefault; // 设置返回键样式 /* UIReturnKeyDefault, UIReturnKeyGo, UIReturnKeyGoogle, UIReturnKeyJoin, UIReturnKeyNext, UIReturnKeyRoute, UIReturnKeySearch, UIReturnKeySend, UIReturnKeyYahoo, UIReturnKeyDone, UIReturnKeyEmergencyCall, UIReturnKeyContinue NS_ENUM_AVAILABLE_IOS(9_0), */ textField.returnKeyType = UIReturnKeyJoin; // 设置输入的字母大小写模式 /* UITextAutocapitalizationTypeNone, UITextAutocapitalizationTypeWords, UITextAutocapitalizationTypeSentences, UITextAutocapitalizationTypeAllCharacters, */ textField.autocapitalizationType = UITextAutocapitalizationTypeWords; // 设置左右视图显示模式 /* 不设置模式,左右视图显示不出来 UITextFieldViewModeNever, UITextFieldViewModeWhileEditing, UITextFieldViewModeUnlessEditing, UITextFieldViewModeAlways */ textField.leftViewMode = UITextFieldViewModeAlways; textField.rightViewMode = UITextFieldViewModeAlways; // 设置左右视图 textField.leftView = label1; textField.rightView = label2; // 让 textField 获取第一响应 /* 打开应用程序或界面时直接弹出键盘 */ [textField becomeFirstResponder]; // 让 textField 放弃第一响应 /* 收起键盘 */ [textField resignFirstResponder]; // 设置 textField 的代理,需遵守协议 <UITextFieldDelegate> textField.delegate = self;

转载于:https://www.cnblogs.com/fantasy940155655/p/5756876.html

相关文章:

  • 静态,抽象类、接口、类库
  • leetcode-188 买卖股票4
  • [转]理解I/O Completion Port
  • canvas实际项目操作,包含:线条,圆形,扇形,图片绘制,图片圆角遮罩,矩形,弧形文字...
  • 【iOS第三方框架】FMDB刚刚好
  • C#框架及概念
  • vue webpack 构建
  • 设计模式之观察者模式(c++)
  • codeforces 492E. Vanya and Field(exgcd求逆元)
  • tcp 重发 应用层重传
  • Log4j具体使用实例
  • ios8之后的界面旋转简单原理
  • 设计模式之桥接模式(Bridge模式)
  • jsdoc文档
  • ESXI虚拟化增加系统盘容量
  • 《Javascript高级程序设计 (第三版)》第五章 引用类型
  • 2017届校招提前批面试回顾
  • angular组件开发
  • happypack两次报错的问题
  • Java-详解HashMap
  • ubuntu 下nginx安装 并支持https协议
  • 安卓应用性能调试和优化经验分享
  • 读懂package.json -- 依赖管理
  • 服务器之间,相同帐号,实现免密钥登录
  • 前端设计模式
  • 让你成为前端,后端或全栈开发程序员的进阶指南,一门学到老的技术
  • 算法之不定期更新(一)(2018-04-12)
  • 微信小程序实战练习(仿五洲到家微信版)
  • 学习HTTP相关知识笔记
  • 掌握面试——弹出框的实现(一道题中包含布局/js设计模式)
  • 这几个编码小技巧将令你 PHP 代码更加简洁
  • #Spring-boot高级
  • #我与Java虚拟机的故事#连载07:我放弃了对JVM的进一步学习
  • ${ }的特别功能
  • (C语言)球球大作战
  • (MonoGame从入门到放弃-1) MonoGame环境搭建
  • (附源码)springboot社区居家养老互助服务管理平台 毕业设计 062027
  • (力扣)循环队列的实现与详解(C语言)
  • (六)Hibernate的二级缓存
  • (学习日记)2024.04.10:UCOSIII第三十八节:事件实验
  • .form文件_SSM框架文件上传篇
  • .NET Framework 和 .NET Core 在默认情况下垃圾回收(GC)机制的不同(局部变量部分)
  • .Net Memory Profiler的使用举例
  • .net websocket 获取http登录的用户_如何解密浏览器的登录密码?获取浏览器内用户信息?...
  • .NET/C# 使窗口永不激活(No Activate 永不获得焦点)
  • .net流程开发平台的一些难点(1)
  • .net中生成excel后调整宽度
  • @Transactional 竟也能解决分布式事务?
  • [100天算法】-目标和(day 79)
  • [20181219]script使用小技巧.txt
  • [bzoj1324]Exca王者之剑_最小割
  • [C++]Leetcode17电话号码的字母组合
  • [IE编程] 如何设置IE8的WebBrowser控件(MSHTML) 的渲染模式
  • [java刷算法]牛客—剑指offer链表有环的入口、反转链表、合并排序链表
  • [LeetCode] 196. 删除重复的电子邮箱