限制UITextField 输入字数
2015-12-04 09:30
513 查看
Objective-C
Swift
StackOverFlow
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { // Prevent crashing undo bug – see note below. if(range.length + range.location > textField.text.length) { return NO; } NSUInteger newLength = [textField.text length] + [string length] - range.length; return newLength <= 25; }
Swift
func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool { let currentCharacterCount = textField.text?.characters.count ?? 0 if (range.length + range.location > currentCharacterCount){ return false } let newLength = currentCharacterCount + string.characters.count - range.length return newLength <= 25 }
StackOverFlow
相关文章推荐
- 使用UItableview在iOS应用开发中实现好友列表功能
- UEFI引导系统
- BroadcastReceiver更新UI
- UITextField输入框 只能输入两位小数
- sql里的in对应linq的写法 及 IQueryable转化为Dictionary
- easyui 布局标题纵向排列
- sql里的in对应linq的写法 及 IQueryable转化为Dictionary
- UITextView根据内容适应大小
- UITextView
- Android Studio aapt.exe finished with non-zero exit value 1
- 修改UITextField的placeHoder字体颜色
- codeforces Queries about less or equal elements 二分
- Bluetooth Low Energy 嗅探
- iOS之UI--自定义IOS的HYCheckBox源码的使用
- chrome 26.0.XXX版本下media query流媒体查询有问题的bug
- WebKit之binding案例分析(testMediaQueryListListener.idl)
- SQL Report Builder 报表里面的常见问题分析
- UITableViewCell的几种创建和加载方式
- leetcode笔记:Longest Consecutive Sequence
- iOS UI基础-17.0 UILable之NSMutableAttributedString