Tag: uitextfield

iOS – 为UITextField实现一个类

我有一个UIView ,有很多的UITexfields , UITextField *field1 = [[UITextField alloc] initWithFrame:CGRectMake(135, 292, 50, 20)]; field1.backgroundColor = [UIColor clearColor]; field1.borderStyle = UITextBorderStyleNone; field1.returnKeyType = UIReturnKeyNext; field1.contentVerticalAlignment = UIControlContentVerticalAlignmentBottom; field1.font = [UIFont fontWithName:inputFont size:fontSize]; field1.placeholder = @"size"; [self addSubview:field1]; 我可以创build一个UITextField类并使用这些参数预设创build此类的一个实例吗? – 为了减less代码:(如果我有很多领域的代码变得非常长,重复? 我可以得到一些关于如何设置这个类的帮助! -谢谢

iOS辅助function隐藏“textField,双击编辑”通知

我有一个pickerView作为inputView的textField。 现在,当我开启配音并select文本字段时,配音将读取:“数量:3(textField的内容)”,然后是“textField”,然后是“双击编辑”。 无论如何,配音只是读取内容,并跳过下面的“textField。双击编辑”? 我试图给textField另一个UIAccessibilityTraits /提示,他们不工作。 谢谢!

如何在我的文本框和Foursquare应用程序button周围绘制圆angular矩形

如何在Foursquare iPhone应用程序中的所有button和文本框后面绘制背景? 看看它说“与…共享”

检测用户是否input了UITextField

我知道,如果您使用下面的代码行,您可以检测用户在TEXT VIEW中input的内容。 if ([[textView text] isEqualToString:@"") 我想检测用户是否在文本字段中input了任何内容,而这不适用于文本字段。 我应该改变什么? 谢谢你的帮助!

如何检查UITextField值的特定types的字符,例如字母或数字?

我想要做的就是在下面的if语句中设置一些布尔值为true,如果textField中包含字母,数字,破折号和空格以外的任何内容。 然后在电子邮件字段中检查有效的电子邮件。 这是我如何检查长度: if countElements(textField.text!) < 2 || countElements(textField.text) > 15 { errorLabel.text = "Name must have between 2 and 15 characters." self.signUpView.signUpButton.enabled = false } else { errorLabel.text = "" self.signUpView.signUpButton.enabled = true } 这个if语句在UITextFieldDelegate方法的textFielddidEndEditing里面。 我有一种感觉,我将不得不使用某种forms的正则expression式来检查一个有效的电子邮件。 使用正则expression式来检查一个字段是否只包含我允许的字符,并返回一个布尔值,告诉我文本字段是否包含不允许的字符,这样才能显示错误信息。 有没有一些首选的方法来做到这一点? 在Objective-C中,我使用NSCharacterSet,但不知道如何在这里实现。 谢谢你的时间

在Swift中格式化电话号码

我正在格式化我的文本文本文本,一旦用户开始input电话号码到这种格式types0 (555) 444 66 77 ,它工作正常,但一旦我从服务器得到的号码我得到这样的05554446677所以,请你能告诉我,一旦我从服务器上得到它,我怎样才能以相同的格式编辑它? 我的代码一旦开始input: func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool { if textField == phoneNumberTextField{ var newString = (textField.text as NSString).stringByReplacingCharactersInRange(range, withString: string) var components = newString.componentsSeparatedByCharactersInSet(NSCharacterSet.decimalDigitCharacterSet().invertedSet) var decimalString = "".join(components) as NSString var length = decimalString.length var hasLeadingOne = length > 0 && decimalString.characterAtIndex(0) == (1 […]

开始编辑和键盘时,在textField上滚动

我有一个由UIImageView组成的viewController,填充整个视图和两个位于视图中心的textField。 所有这些都位于ScrollView中。 我使用故事板,我禁用了自动布局。 当我点击一个textField,从而打开键盘,我希望滚动直接在textField上移动。 我怎样才能做到这一点?

UITextField – 为leftView添加UIView – 无法获得焦点

在我的应用程序的UITextFields有占位符文本定义(在界面生成器),我不能让这些领域获得焦点(即显示键盘,并允许编辑),当我点击占位符文本占用的区域。 如果我点击占位符文本区域以外的文本区域(虽然仍然在文本文件本身的范围内),它将正常运行(即popup键盘,我可以编辑文本区域的内容)。 我怎样才能解决这个问题? 谢谢。 编辑1 好的,我想我已经明白了。 我还设置了这些UITextFields的“leftView”属性的空白视图。 如果我删除它,可以触摸占位符文本区域中的UITextFields,并按预期做出反应; 尽pipe我需要这个视图。 如果你把这个spacer视图的背景颜色改成红色的,你可以看到它根本不挡道,所以我不知道发生了什么问题。 为什么这个代码会导致这个问题? 谢谢。 +(UIView*)getTextFieldLeftSpacerViewWithBackgroundColor:(UIColor*)backgroundColor andHeight:(CGFloat)height { UIView *leftWrapper = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 8.0f, height)]; leftWrapper.autoresizingMask = UIViewAutoresizingNone; [leftWrapper setOpaque:YES]; if(backgroundColor){leftWrapper.backgroundColor = backgroundColor;} else{leftWrapper.backgroundColor = [UIColor clearColor];} return [leftWrapper autorelease]; } +(void)setTextFieldLeftSpacerForTextFieled:(UITextField*)textField { if(textField) { UIView *spacer = [MYViewController getTextFieldLeftSpacerViewWithBackgroundColor:nil andHeight:textField.bounds.size.height]; textField.leftView = spacer; textField.leftViewMode = […]

在iOS7中的UITextFields之间进行点击

当selectUITextField并显示键盘时,如果点击视图的其他部分,则键盘消失。 如果我点击另一个UITextField ,键盘保持不变,第一个文本字段被取消select,什么都不会发生。 然后我需要点击另一个UITextFIeldselect发生和键盘出现。 有没有办法使第二个UITextField立即访问时,第一个UITextField被选中?

用于UITextField和UITextView的UITextInput协议用法来pipe理崩溃时的select结果

UITextField和UITextView都采用UITextInput协议。 UITextView的selectedRange属性返回NSRange,其中UITextField没有任何select属性/方法。 我想使用一个例程来pipe理UITextField或UITextView的插入。 所以我做了以下几点: id<UITextInput> textInput = nil; if ([self.aTextView isFirstResponder]) { textInput = self.aTextView; } else if ([self.aTextField isFirstResponder]) { textInput = self.aTextField; } if (textInput != nil) { UITextRange * selectedRange = textInput.selectedTextRange; // … } 只有在selectedTextRange属性中,“发送到实例的无法识别的select器”会立即崩溃。 我究竟做错了什么? [编辑:似乎在iOS 5中工作,但在iOS 4设备上崩溃。这是iOS 5中的更改吗? 文档说协议是3.2+。]