uitextfield

禁止UITextField 使用粘贴复制功能

前提是你 提交于 2020-04-06 23:52:15
在开发中有时候会遇到这样的需求,就是一个文本框里面的内容不允许用户复制,或者不允许用户将其它地方复制的内容粘贴进来,本文交给你怎么实现禁止 UITextField 的粘贴、复制。 在 UITextField 中有这样一个方法:-canPerformAction:withSender:,下面来重写这个方法: - (BOOL)canPerformAction:(SEL)action withSender:(id)sender{ NSLog(@"%@", NSStringFromSelector(action)); return YES; } 运行程序,长按文本框,会出现一个菜单: 你看,剪切、复制、选择、粘贴等功能都在里面了,只要让你不希望有的功能不出现在这个菜单上,或者干脆没有这个菜单就能达到我们的目的了。 怎么弄呢? 还记得上面重写的那个方法吗?看看控制台打印了啥吧: 这都是在长按文本框的时候打印的。你看 -cut: -cop: -paste: 这些方法都在这里,再结合这个方法的名字就能明白了,在弹出那个菜单之前,系统会调用 - canPerformAction:withSender: 这个方法一一判断每个功能是否允许使用。所以只需要在对应的action出现的时候返回NO就可以了: - (BOOL)canPerformAction:(SEL)action withSender:

How to implement TextField search bar to filter tableview values Swift

。_饼干妹妹 提交于 2020-03-25 22:04:37
问题 I have created a custom textField bar on top of the ViewController to filter data values in UITableView . As I have a nested type of JSON so couldn't properly get how to use filter for it. I want to implement textField as a search bar with TableView. screenshot attached. Value which I need to filter is pickList -> textField textSearchChange function added for text search. Data is section wise and then values and is already displaying in tableView. Model: struct SectionList : Codable { let

How to implement TextField search bar to filter tableview values Swift

元气小坏坏 提交于 2020-03-25 22:03:34
问题 I have created a custom textField bar on top of the ViewController to filter data values in UITableView . As I have a nested type of JSON so couldn't properly get how to use filter for it. I want to implement textField as a search bar with TableView. screenshot attached. Value which I need to filter is pickList -> textField textSearchChange function added for text search. Data is section wise and then values and is already displaying in tableView. Model: struct SectionList : Codable { let

使用代理控制点击输入框,键盘升起,页面上升

纵饮孤独 提交于 2020-03-06 10:47:08
// // ViewController.m // 控制键盘显示页面自动上升 // // Created by dc0061 on 16/1/4. // Copyright © 2016 年 dc0061. All rights reserved. // #import "ViewController.h" @interface ViewController () { UITextField *text; UITextField *text1; UILabel *label; } @end @implementation ViewController - ( void )viewDidLoad { [ super viewDidLoad ]; label = [[ UILabel alloc ] initWithFrame : CGRectMake ( 100 , 100 , 175 , 40 )]; label . text = @" 测试 " ; [ self . view addSubview : label ]; text = [[ UITextField alloc ] initWithFrame : CGRectMake ( 100 , 550 , 175 , 40 )]; text . textAlignment = NSTextAlignmentCenter ;

Entering text into textfield causing uipangesture object to move back to its orginal position

谁说胖子不能爱 提交于 2020-03-04 19:40:10
问题 The bounty expires in 2 days . Answers to this question are eligible for a +50 reputation bounty. Mitch Mustain is looking for an answer from a reputable source : Just get a a uiimageview to move using uipangesutre and when text is enter into the textfield. The imageview does not return to its original position. My swift code below has a image view connected to a pangesture. When something is entered into a textfield when after the image view is moved. The image view reverts back to its

iOS开发3:UITextField控件的属性

自古美人都是妖i 提交于 2020-02-29 10:08:19
在 Xcode 4.2 中使用 IB 给视图拖上去一个文本框后,选中文本框,可以在Attribute Inspector中设置其各种属性。 Attribute Inspector 分为三部分,分别是 Text Field、Control 和 View 部分。我们重点看看 Text Field 部分。 Text Field 部分有以下选项: 1、Text :设置文本框的默认文本。 2、Placeholder : 可以在文本框中显示灰色的字,用于提示用户应该在这个文本框输入什么内容。当这个文本框中输入了数据时,用于提示的灰色的字将会自动消失。 3、Background : 4、Disabled : 若选中此项,用户将不能更改文本框内容。 5、接下来是三个按钮,用来设置对齐方式。 6、Border Style : 选择边界风格。 7、Clear Button : 这是一个下拉菜单,你可以选择清除按钮什么时候出现,所谓清除按钮就是出一个现在文本框右边的小 X ,你可以有以下选择: 7.1 Never appears : 从不出现 7.2 Appears while editing : 编辑时出现 7.3 Appears unless editing : 7.4 Is always visible : 总是可见 8、Clear when editing begins : 若选中此项

UITextField控件的属性

混江龙づ霸主 提交于 2020-02-29 10:03:05
UITextField控件的属性 在 Xcode 4.5 中使用 IB 给视图拖上去一个文本框后,选中文本框,可以在Attribute Inspector中设置其各种属性。( 其它控件也几乎拥有如下相关属性 ) Attribute Inspector 分为三部分,分别是 Text Field、Control 和 View 部分。 Text Field 部分有以下选项: 1、Text :设置文本框的默认文本。 2、Placeholder : 可以在文本框中显示灰色的字,用于提示用户应该在这个文本框输入什么内容。当这个文本框中输入了数据时,用于提示的灰色的字将会自动消失。 3、Background : 4、Disabled : 若选中此项,用户将不能更改文本框内容。 5、接下来是三个按钮,用来设置对齐方式。 6、Border Style : 选择边界风格。 7、Clear Button : 这是一个下拉菜单,你可以选择清除按钮什么时候出现,所谓清除按钮就是出一个现在文本框右边的小 X ,你可以有以下选择: 7.1 Never appears : 从不出现 7.2 Appears while editing : 编辑时出现 7.3 Appears unless editing : 7.4 Is always visible : 总是可见 8、Clear when editing

IOS UITextField

梦想与她 提交于 2020-02-29 04:26:57
// UITextField的初始化 UITextField textField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 320,30)]; //外框类型 [textField setBorderStyle:UITextBorderStyleRoundedRect]; //默认显示的字 textField.placeholder = @" 默认显示的字 "; //密码 textField.secureTextEntry = YES; //是否纠错 text.autocorrectionType = UITextAutocorrectionTypeNo; typedef enum { UITextAutocorrectionTypeDefault, 默认 UITextAutocorrectionTypeNo, 不自动纠错 UITextAutocorrectionTypeYes, 自动纠错 } UITextAutocorrectionType; //首字母是否大写 textField.autocapitalizationType = UITextAutocapitalizationTypeNone; typedef enum { UITextAutocapitalizationTypeNone, 不自动大写

设置UITextField的最大字符长度

半世苍凉 提交于 2020-02-27 04:32:04
加载 UIView 时,如何在iPhone SDK的 UITextField 设置最大字符数? #1楼 这应该足以解决问题(将4替换为您想要的限制)。 只要确保在IB中添加委托即可。 - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { NSString *newString = [textField.text stringByReplacingCharactersInRange:range withString:string]; return (newString.length<=4); } #2楼 通常,您有多个长度不同的输入字段。 - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { int allowedLength; switch(textField.tag) { case 1: allowedLength = MAXLENGTHNAME; // triggered for

使用UITextBorderStyleNone为UITextField设置填充

一笑奈何 提交于 2020-02-26 02:57:10
我想为我的 UITextFields 使用自定义背景。 这工作正常,除了我必须使用 UITextBorderStyleNone 使它看起来漂亮。 这会强制文本粘在左边而不进行任何填充。 我可以手动设置填充,使其看起来类似于 UITextBorderStyleRoundedRect 除了使用我的自定义背景图像? #1楼 另一个考虑因素是,如果你有多个 UITextField 添加填充,就是为每个文本字段创建一个单独的 UIView - 因为它们无法共享。 #2楼 我基于Nate的解决方案,但后来我发现当你使用leftView / rightView属性时这会导致问题,所以它更好地调整了super的实现,因为它会考虑左/右视图。 - (CGRect)textRectForBounds:(CGRect)bounds { CGRect ret = [super textRectForBounds:bounds]; ret.origin.x = ret.origin.x + 5; ret.size.width = ret.size.width - 10; return ret; } - (CGRect)editingRectForBounds:(CGRect)bounds { return [self textRectForBounds:bounds]; } #3楼