uitextfield

Swift how to assign a string to a UITextField?

会有一股神秘感。 提交于 2019-12-07 01:16:30
@IBOutlet weak var resultProcessed: UITextField! var str:String = "Mike is here" resultProcessed = str gives error: Cannot assign a value of type 'String' to a value of type 'UITestField!' resultProcessed.text = str You need to assign it to the text property. 来源: https://stackoverflow.com/questions/30093423/swift-how-to-assign-a-string-to-a-uitextfield

How to determine the cursor position of a UITextField?

十年热恋 提交于 2019-12-07 01:01:36
I have a text field that is always of the format "XX0000000XX", X being a letter, 0 being a number. I switch keyboards as the user is typing depending on whether they need to enter a number or letter. This works fine, until the user positions the cursor in the middle of the text field to make an edit. How do I determine the cursor position within a UITextField? I know a UITextView has a selectedRange that can be used, but I've read that you can't force a UITextView to be single line entry? i.e. Disable multiple lines of text. Clever bit with the keyboards. My immediate thought is that perhaps

iOS 正则表达式判断UITextField是否为全汉字,全字母,全数字,数字和字母

这一生的挚爱 提交于 2019-12-07 00:43:55
判断全汉字(这个问题苦恼了我很久,现在很方便,几行代码就搞定): if ([ self deptNameInputShouldChinese ]) { [ DemonAlertHelper showToastWithMessage : @" 只能是中文 " ]; return ; } 调用这个方法就可 #pragma mark-- #pragma mark 输入中文 - ( BOOL ) deptNameInputShouldChinese { NSString *regex = @"[\u4e00-\u9fa5]+" ; NSPredicate *pred = [ NSPredicate predicateWithFormat : @"SELF MATCHES %@" ,regex]; if (![pred evaluateWithObject : inputTextField . text ]) { return YES ; } return NO ; } 判断全数字: - ( BOOL ) deptNumInputShouldNumber { NSString *regex = @"[0-9]*" ; NSPredicate *pred = [ NSPredicate predicateWithFormat : @"SELF MATCHES %@" ,regex]; if (

Reactive Cocoa - UITextView's rac_textSignal doesn't get called when programmatically setting text

匆匆过客 提交于 2019-12-07 00:16:58
问题 I'm implementing a chat UI, and using Reactive Cocoa to adjust the chat bubble's size as the user types. Currently, I'm updating the UI's layout based on the textview's rac_textSignal . Everything's working great - except for one bit: when the user sends the message, I programmatically clear the textfield: _inputTextView.text = @""; ... but the textview's rac_textSignal doesn't activate. I hear this is a feature with ReactiveCocoa - but what's the proper way to build this? Do I need to have

How to select all text in a UITextField using Swift

狂风中的少年 提交于 2019-12-06 22:49:43
问题 I'm using below code, but for some reason it's not working. Any idea? textField.text = "Hello" textField.becomeFirstResponder() textField.selectedTextRange = self.textField.textRangeFromPosition(self.textField.beginningOfDocument, toPosition: self.textField.endOfDocument) This is what I get: 回答1: I had the same problem and I solved like this: First, implement UITextFieldDelegate in your ViewController class ViewController : UITextFieldDelegate Then, set your textField delegate to "self"

Set UITextField placeholder color programmatically

血红的双手。 提交于 2019-12-06 21:58:00
问题 How to set UITextField place holder color programmatically in swift? 回答1: 1 - Create an AttributedString with colour you want. 2 - Set this AttributedString to the textfield attributedPlaceholder property let placeholder = NSAttributedString(string: "Some", attributes: [NSForegroundColorAttributeName : UIColor.redColor()]) let textField = UITextField(frame: CGRect(x: 0, y: 0, width: 100, height: 30)); textField.attributedPlaceholder = placeholder; self.view.addSubview(textField) From apple

A static character prefix in UITextField

一笑奈何 提交于 2019-12-06 19:46:21
问题 Is there a built-in way to add a character prefix to a UITextField like the screenshot below? If no, what is the best, most straight-forward way to accomplish this? I am thinking the background property might be able to do this. 回答1: Simply adding a gray UILabel on top of the UITextField does the trick: Note that the UILabel behaves like a background image, the entered text stays on top: UPDATE Additionally you can add some padding to the UITextField using the following code: UIView

How to stop my Custom Keyboard from 'floating' or being undocked on iPad

↘锁芯ラ 提交于 2019-12-06 17:27:32
问题 I have a custom Keyboard that gets displayed for a certain UITextField when I set the textField's inputView to my KeyboardView. The keyboard works fantastically well but it has become apparent that the keyboard will 'float' if the user has previously undocked the built in Apple Keyboard or indeed split it. I have searched for many hours for a way to ensure my custom keyboard does not act like this and instead stays docked to the bottom of the screen regardless as to whether the user has

Can't type text into UITextField or UITextView in iOS6

故事扮演 提交于 2019-12-06 17:00:47
问题 In one of my apps, when I try to edit (type some text) UITextField , UITextView or any other 'text-able' UIControl the cursor just blinks but no characters are typed in except BACKSPACE (possible only when I have some initial text in it), RETURN and switching character types. This goes to all controls across whole application. Summary: It happens only from iOS 6.0 (does not occur on iOS 5.x, 4.x neither Simulator or real device) All delegate methods are fired (shouldBeginEditing:

Issue in UITextField add inside UIImageView in iPhone?

半腔热情 提交于 2019-12-06 16:46:21
问题 Currently i am working in iPhone app, Using UIImageView to set a background image on the screen, then add UITextField inside the UIImageView, then i run the app, the UITextField cannot enabled, How to enable this? please help me Thanks in Advance I tried this: UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)]; imageView.image=[UIImage imageNamed:@"2ndscreenback.png"]; Daystext =[[UITextField alloc]initWithFrame:CGRectMake(57, 122, 171, 31)]; Daystext