uitextfield

(iOS)修改UITextField高度

我怕爱的太早我们不能终老 提交于 2019-12-09 13:48:39
修改UITextField高度 === --- ## 是否可以通过修改frame改变高度 网上流传的代码中使用如下一份代码: // 以下代码任然不能改变UITextField高度 CGRect rect = _userNameField.bounds; rect.size.height = 88; rect.size.width = 20; _userNameField.bounds = rect; 经过尝试高度固定不变,固该代码不可以实现我们的目的。 --- ## 通过自定义子类实现修改UITextField高度 在子类中覆盖``- (CGRect)borderRectForBounds:(CGRect)bounds``方法,即可 /** * 通过以下代码实现设置文本框高度 * 44是所希望的高度 */ - (CGRect)borderRectForBounds:(CGRect)bounds { bounds.size.height = 44; return bounds; } >### Parameters >* bounds > > The bounding rectangle of the receiver. > >* Return Value > > The border rectangle for the receiver. 来源: oschina 链接: https:

UITextField 基本设置

跟風遠走 提交于 2019-12-09 13:43:30
UITextField--基本设置 iPhone UITextField - Change placeholder text color 1、 UILabel的基本设置 2、UITextFiel的基本设置 3、设置UITextFiel输入长度的限制 4、弹出提示消息 5、UITextFiel输入时自动隐藏键盘 - (void)LY_Display { UILabel *LY_Label = [[UILabel alloc] initWithFrame:CGRectMake(60, 180, 60, 30)]; [self.view addSubview:LY_Label]; LY_Label.backgroundColor = [UIColor clearColor]; LY_Label.text = @"密 码"; LY_Label.font= [UIFont fontWithName:@"zapfino" size:(15.0f)]; //字体设置 UITextField *LY_Text = [[UITextField alloc] initWithFrame:CGRectMake(143, 180, 80, 30) ]; [self.view addSubview:LY_Text]; LY_Text.backgroundColor = [UIColor whiteColor

How to show keyboard after used inputView

╄→尐↘猪︶ㄣ 提交于 2019-12-09 10:50:02
问题 I used inputView to show uipickerview for my textfield , but I use same textfield for other functions. How can I show standard keyboard after I used inputView for that textfield ? textfield.inputView = pickrView; 回答1: Just textfield.inputView = nil; worked for me 回答2: As Pavel Kaljunen said, you need only to set the inputView to nil, but when the keyboard is already visible, you have to resignFirstResponder first, set the inputView to nil and then becomeFirstResponder again. [UIView

UITextView和UITextField字数输入控制

末鹿安然 提交于 2019-12-09 10:49:57
上代码 UITextView //每次TextView输入或删除的时候都会调用这个协议方法 <UITextViewDelegate> -(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text { //用指定的字符串替换字符串,返回新的字符串 NSString * new = [textView.text stringByReplacingCharactersInRange:range withString:text ]; //保证新建通知的内容输入框最多只能输入4个字 NSInteger res = 4 - new.length; if (res >= 0) { return YES; }else{ return NO; } } 但是这个方法如果输入是中文或者是联想词的时候都会出现问题,这是因为这个方法 NSString * new = [textView.text stringByReplacingCharactersInRange:range withString:text ]; 不识别中文以及联想词。 在加一个这个就可以了 -(void)textViewDidChange:(UITextView *

UITextField限制输入长度,修改placeholder颜色和大小

醉酒当歌 提交于 2019-12-09 10:49:42
一.修改placeholder的字体大小和颜色 iOS 6 之前使用KVC改变placeholder的字体颜色和大小 [textField setValue:[UIColor redColor]forKeyPath:@"_placeholderLabel.textColor"]; [textField setValue:[UIFontboldSystemFontOfSize:14]forKeyPath:@"_placeholderLabel.font"]; iOS6之后还可以使用attributedPlaceholder来设置 UITextField *textField = [[UITextField alloc]initWithFrame:CGRectMake(0, 0, 200, 200)]; NSString *holderText = @"hello world!"; NSMutableAttributedString *placeholder = [[NSMutableAttributedString alloc]initWithString:holderText]; [placeholder addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0,

UITextField常用属性及设置

孤街醉人 提交于 2019-12-09 10:48:49
定义一个TextField userNameField = [[UITextField alloc] initWithFrame:CGRectMake(userNameImg.frame.origin.x+30,userNameImg.frame.origin.y, 165, 40)]; 1. userNameField.placeholder = @"User Name"; userNameField .attributedPlaceholder= [[NSAttributedString alloc] initWithString:@"手机号码" attributes:@{ NSForegroundColorAttributeName:placeHolderColor}]; 上面这句是设置placeHolder的颜色, placeHolderColor是自己需要的颜色 userNameField.backgroundColor = [UIColor clearColor]; userNameField.delegate = self; userNameField.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter; userNameField

UITextField常用属性

二次信任 提交于 2019-12-09 10:48:38
UITextField是我们经常用的之一但是常用的属性都很熟悉,有些不常用的我也总结下,例如下面的: UIImageView * myView = [[ UIImageView alloc]initWithImage:[UIImage imageNamed:@"face.png"]]; UIImageView * myView2 = [[ UIImageView alloc]initWithImage:[UIImage imageNamed:@"face.png"]]; UITextField *myTextField=[[UITextField alloc]initWithFrame:CGRectMake(40, 40, 240, 60)]; //初始化一个UITextField的frame myTextField.textColor=[UIColor redColor]; //UITextField 的文字颜色 myTextField.delegate=self;//UITextField 代理方法设置 myTextField.placeholder=@"输入密码";//UITextField 的初始隐藏文字,当然这个文字的字体大小颜色都可以改,重写uitextfield,下次介绍 myTextField.textAlignment=UITextAlignmentCenter;

UITextField详解之一:UITextField基本属性

拈花ヽ惹草 提交于 2019-12-09 10:48:23
UITextField是IOS开发中用户交互中重要的一个控件,常被用来做账号密码框,输入信息框等。创建一个用于输入的UITextField其实很简单,在平时使用中,更多的是需要 UITextField和其他UI控件之间进行交互。 1、UITextField的创建 创建一个UITextField其实很容易,代码如下,只需2行就搞定了。 UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(50, 100, 100, 30)];[self.view addSubview:textField]; 可是这么写完,你会发现一个问题就是,我明明创建了UITextField,怎么在视图上看不到??原因就是UITextField默认的背景色是ClearColor,当然我们就看不到上面代码所创建的UITextField了。那可能会想,改下UITextField的背景颜色,不就可以看到了么??那咱们接下来就给UITextField添加一个背景色吧。 textField.backgroundColor = [UIColor redColor]; 效果咱可以看下: 额,这个样式咱就先不要吐槽了⊙﹏⊙,至少,你要的UITextField已经出现在你的眼前了。点击这个UITextField,系统会自动弹出键盘

How to add text field to inputAccessoryView and make the textView first responder

邮差的信 提交于 2019-12-09 10:28:50
问题 My code: - (void)viewDidLoad { [super viewDidLoad]; CGRect rectFake = CGRectZero; UITextField *fakeField = [[UITextField alloc] initWithFrame:rectFake]; [self.view addSubview:fakeField]; UIView *av = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 0.0, 39.0)]; av.backgroundColor = [UIColor darkGrayColor]; CGRect rect = CGRectMake(200.0, 4.0, 400.0, 31.0); UITextField *textField = [[UITextField alloc] initWithFrame:rect]; textField.borderStyle = UITextBorderStyleRoundedRect; textField.font

How can I enable the UITextField to have only one text/number and navigate through multiple `UITextField`s using Next / Done Button

流过昼夜 提交于 2019-12-09 06:56:36
问题 I have to handle navigate through multiple UITextField s using (Next / Done Button) and now I have to allow only one text/number in each UITextField how could we do that in UITextField as shown in image below I have used following code recently and was able to achieve too but got problem that When I first enter the text/number in UITextField it is being entered in UITextField and when I enter the next text/number for second time it is being used only to push to next UITextField . I want to