uitextfield

How can I add a toolbar above the keyboard?

蓝咒 提交于 2019-12-17 04:44:30
问题 I have created a UIToolBar programmatically and added a UITextField on it. Now, I need that toolbar to be above the keyboard when I click in another text field. UIToolbar *toolBar=[[UIToolbar alloc]initWithFrame:CGRectMake(0,400, 320, 60)]; [self.view addSubview:toolBar]; UITextField *txtView=[[UITextField alloc]initWithFrame:CGRectMake(0, 400, 260, 30)]; txtView.backgroundColor =[UIColor grayColor]; txtView.placeholder=@"Address"; UIBarButtonItem *txtfieldItem=[[UIBarButtonItem alloc

Swift add icon/image in UITextField

点点圈 提交于 2019-12-17 03:47:39
问题 I would like to add icon/image in UITextField. The icon/image should be left to placeholder. I tried this: var imageView = UIImageView(); var image = UIImage(named: "email.png"); imageView.image = image; emailField.leftView = imageView; Thanks. 回答1: Try adding emailField.leftViewMode = UITextFieldViewMode.Always (Default leftViewMode is Never ) Updated Answer for Swift 4 emailField.leftViewMode = UITextFieldViewMode.always emailField.leftViewMode = .always 回答2: Sahil has a great answer and I

How do you dismiss the keyboard when editing a UITextField

拟墨画扇 提交于 2019-12-17 03:45:58
问题 I know that I need to tell my UITextField to resign first responder when I want to dismis the keyboard, but I'm not sure how to know when the user has pressed the "Done" key on the keyboard. Is there a notification I can watch for? 回答1: I set the delegate of the UITextField to my ViewController class. In that class I implemented this method as following: - (BOOL)textFieldShouldReturn:(UITextField *)textField { [textField resignFirstResponder]; return NO; } 回答2: If you connect the DidEndOnExit

How to disable copy paste option from UITextField programmatically

喜夏-厌秋 提交于 2019-12-17 02:36:29
问题 I am making a registration alertview that has a UITextField in it where the user can enter their registration number. everything is pretty much their, however I would like to remove the copy paste function from the textfield programmatically since their is no InterfaceBuilder version of the textfield I have no idea how to do this.. here Is my UIalertview thus far... - (void)pleaseRegisterDevice { UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@"Please Register Device!" message:

iPad keyboard will not dismiss if modal ViewController presentation style is UIModalPresentationFormSheet

大憨熊 提交于 2019-12-16 22:35:19
问题 Note: See accepted answer (not top voted one) for solution as of iOS 4.3. This question is about a behavior discovered in the iPad keyboard, where it refuses to be dismissed if shown in a modal dialog with a navigation controller. Basically, if I present the navigation controller with the following line as below: navigationController.modalPresentationStyle = UIModalPresentationFormSheet; The keyboard refuses to be dismissed. If I comment out this line, the keyboard goes away fine. ... I've

iPhone UITextField - Change placeholder text color

筅森魡賤 提交于 2019-12-16 22:09:09
问题 I'd like to change the color of the placeholder text I set in my UITextField controls, to make it black. I'd prefer to do this without using normal text as the placeholder and having to override all the methods to imitate the behaviour of a placeholder. I believe if I override this method: - (void)drawPlaceholderInRect:(CGRect)rect then I should be able to do this. But I'm unsure how to access the actual placeholder object from within this method. 回答1: Since the introduction of attributed

How to input currency format on a text field (from right to left) using Swift?

北城以北 提交于 2019-12-16 19:44:38
问题 I have a number let’s say 0.00 . When the user taps 1. We should have 0.01 When the user taps 2. We should display 0.12 When the user taps 3. We should display 1.23 When the user taps 4. We should display 12.34 How can I do that with Swift? 回答1: For Swift 3 . Input currency format on a text field (from right to left) override func viewDidLoad() { super.viewDidLoad() textField.addTarget(self, action: #selector(myTextFieldDidChange), for: .editingChanged) } func myTextFieldDidChange(_ textField

UITextField with a placeholder containing an image and text

醉酒当歌 提交于 2019-12-14 02:35:44
问题 is there any way I could have a magnifier icon stuck to my placeholder in a UITextField like the below: I tried to override leftViewRectForBounds(bounds: CGRect): override func leftViewRectForBounds(bounds: CGRect) -> CGRect { var superRect = super.leftViewRectForBounds(bounds) superRect.origin.x += 80 return superRect } but it didn't work 回答1: You can add images to text using NSAttributedString and NSTextAttachment . I haven't used them in a while but I believe you can do something like this

How to save text field value in uicollectionviewcell

点点圈 提交于 2019-12-14 02:18:21
问题 hi i have text field in uicollectionviewcell so what i need it example : when i edit text filed value in row 5 and i done it and go to text filed in row 20 to edit value the collectionview has reloaded and forget value in row 5, so i need way to save value temporarily while do I change it manually this my code : cell.foodNumber.tag = indexPath.row if let foodcodes = self.menu![indexPath.row]["code"] as? NSString { if contains(self.indexPathsForSelectedCells, indexPath) { cell

iOS 5 upgrade changed font appearance

泄露秘密 提交于 2019-12-14 02:05:00
问题 My app uses the "♥ BLACK HEART SUIT Unicode: U+2665, UTF-8: E2 99 A5" and "♡ WHITE HEART SUIT Unicode: U+2661, UTF-8: E2 99 A1" characters in UITextFields and in some UITableViewCell's titles. Since upgrading target iPhone to iOS 5, the "white heart suit" still displays as expected BUT the "black heart suit" now displays as a graphic; a red heart on a white field. This is unwelcome. How can I get back to where I once belonged, that is, with the font simply displaying the character and not