uitextfield

Force lowercase - ios swift

元气小坏坏 提交于 2019-12-10 14:49:44
问题 I would like to force lowercase in an UITextfield when the user is typing. I came out so far with this code, but seems like it's not lowering characters. func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool { if string.characters.count == 0 { return true } let currentText = textField.text ?? "" let prospectiveText = (currentText as NSString).stringByReplacingCharactersInRange(range, withString: string.lowercaseString)

UITextField in iOS7 simulator do not take any input from mac keyboard

≡放荡痞女 提交于 2019-12-10 13:36:50
问题 UITextField suddenly do not take any input from mac keyboard, However I am able to use the virtual keyboard coming up on UIView on iOS7.0 simulator. Has any one resolved this issue before? 回答1: In simulator menu: Hardware -> Keyboard -> Connect Hardware Keyboard helped me with this problem 回答2: I reset the iOSSimulator , its contents and settings and quit and relaunched the iOS-simulator. it worked. This exactly happened when I updated the code from SVN . I guess its always a good practice to

textFieldShouldEndEditing called multiple times

旧城冷巷雨未停 提交于 2019-12-10 13:17:15
问题 I am working on a view that has multiple UITextField objects. My view controller serves as the UITextFieldDelegate , and I've implemented the (BOOL)textFieldShouldEndEditing:(UITextField *)textField method to save and validate the record being displayed. If the user clicks on the "Done" button after editing an item and the save/validate fails, then a UIAlertView is displayed and the user is kept on the UITextField that fails validation. My problem is this -- when a user clicks from the

How can I detect a KeyPress event in UITextField?

前提是你 提交于 2019-12-10 12:59:08
问题 In UITextView there is a Changed event to handle keypress. However the UITextField has not such event. How can I detect a KeyPress event in UITextField ? There is a method described here using notifications, however the problem I have is that I cannot unsubscribe from the TextFieldTextDidChangeNotification. 回答1: I'm not sure which is your question. The first one you seem to have answered yourself, i.e. the solution (from your link) is to use NSNotificationCenter.DefaultCenter.AddObserver .

How can I change a UITextField position in UISearchBar?

﹥>﹥吖頭↗ 提交于 2019-12-10 12:58:26
问题 Is there a way to reposition UITextField inside UISearchBar? I'd like to move UITextField inside UISearchBar up a little bit. 回答1: The UITextField approach is not working anymore, probably due to a restyling of the UISearchBar object. UISearchBar resizes its UITextField when it is presented on screen, this invalidates all manipulations on the UITextField. However, I discovered that UISearchBar responds to the setContentInset: method (tested on iOS 5.0.1). It adjusts the inset distance from

How do I detect if a text field has text in it rather than a numerical value?

拟墨画扇 提交于 2019-12-10 12:24:49
问题 I have a text field which the user enters a number and it gets converted to an integer. The keyboard set is to decimal numerical one. Except the paste function is still enabled so the user can paste text into it. I want to set it to change a label to @"error" if the user enters a non numerical value into it. I do not want to disable the paste function as I still want the user to have the ability to copy and paste their own numerical values into my app. 回答1: If you want apply restriction that

UITextField right frame

☆樱花仙子☆ 提交于 2019-12-10 12:05:42
问题 I have a piece of code like this: CGSize lSize = [@"Hello World" sizeWithFont:[UIFont fontWithName:@"Arial" size:13]]; Now I want to have the right frame to see this text in the UITextField . I don't want to change the font size just have the frame for UITextField to fit with this text. I will really appreciate any help 回答1: #define MAIN_FONT_SIZE 17 #define MIN_MAIN_FONT_SIZE 11 #define MAX_TEXT_WIDTH 100 CGPoint point; CGFloat actualFontSize; CGSize size; UIFont *mainFont = [UIFont

Dimiss keyboard when editing textfield on UIWebview

帅比萌擦擦* 提交于 2019-12-10 11:01:18
问题 I'm opening a web page on UIWebview and this page has a textfield and a virtual keyboard the to enter password. But when edit the textfield iPhone virtual keyboard appears as well. I wanted to dismiss iPhone keyboard and on the same time continue editing the textfield. I have tried the following but it did not work. [webView stringByEvaluatingJavaScriptFromString:@"document.activeElement.blur()"]; And also tried to register for Keyboard notification so I can dimiss the keyboard but did not

Keyboard hides UITextField. How to solve this?

ε祈祈猫儿з 提交于 2019-12-10 10:58:37
问题 I have a textField which is at bottom of the screen. When I begin editing, the keyboard appears and hides the textField. Can anyone suggest how to solve this? 回答1: Generally you would put your content in a scroll view and move your scroll view up when the keyboard appears. There are many tutorials out there so google them. Here is one of them. 回答2: You can use following code in two diffrent method, call it when editing began and end, to move your view up and down,(just change the valuew that

Weird behaviour of Caret/Cursor in UITextField

我怕爱的太早我们不能终老 提交于 2019-12-10 10:39:23
问题 (Xcode10.1 ,Swift, iOS 11&12) Question: How to increase height of caret/cursor in UITextField What i've tried so far: i've done this, and problem solved. class BPTextField: UITextField { override func caretRect(for position: UITextPosition) -> CGRect { //CGRect rect = [super caretRectForPosition:position]; var rect = super.caretRect(for: position) let h = self.frame.height - 5 let y_ = (self.frame.height - h)/2 rect.origin.y = y_ rect.size.height = h; return rect; } } but, when i changed