I want to present emoji panel and using NSApp.orderFrontCharacterPalette(nil). it works fine, but sometimes it appears at random place and i want it to be "constrained" to text field where I'm going to use it. Can i set frame of panel manually or do it in another way? thanks for help
It requires your text field to be the first responder.
You could make a text field the first responder by calling following method:
Swift:
textField.window?.makeFirstResponder(textField)
Objective-C:
[[textField window] makeFirstResponder:textField];
Hope it helps.
Related
I am using the following tutorial to show the uitextfield above the keyboard at all times:
http://mobile.tutsplus.com/tutorials/iphone/ios-sdk-keeping-content-from-underneath-the-keyboard/
But the problem is the uitextfield only gets shown above the keyboard if the person starts typing into the field, but not if the cursor is in the textfield.
How can I change it so that the uitextfield gets shown above the keyboard once the cursor is in the UITextField?
Thanks
Check UITextFieldDelegate and select appropriate method.
In this tutorial they use textFieldDidBeginEditing method to assign active textfield.
As it clear from method name, it executes when someone start typing in text field.
I downloaded the sample code and work just fine for me. The only thing that I figured you could misunderstood is in the case the keyboard it's already below the textField, in these cases the view will not scroll.
I hope this helps. If it's not this that you want, please tell me more about it.
I needed to add a UIKeyboardTypeDecimalPad keyboard to a decimal field, which can only be done programatically. I need the full code (I'm pretty new to Objective-C) to make a UIKeyboardTypeDecimalPad pop up when someone touches inside the text box. I'd also like to add the text field programmatically.
Basically, I need to add a text field with a UIKeyboardTypeDecimalPad keypad. Or, if possible, just the keypad to a text field made in Interface Builder.
Does anyone know a good tutorial for this or can anyone give me the full code themselves, and tell me where I need to put it (the .m or .h or what?)?
Thanks!
Update: As mentioned in the comment below, could I see example code for an app that does this?
To set the keyboard type to UIKeyboardTypeDecimalPad, just assign that value to the text field's keyboardType property.
textField.keyboardType = UIKeyboardTypeDecimalPad;
Adding a text field programmatically is only slightly more work: UITextField *textField = [[[UITextField alloc] initWithFrame:frame] autorelease]; to create it, then set any properties you need to set, and add it to the appropriate view with addSubview:.
In your view controller's viewDidLoad method is a good place for this sort of thing. Or if you're loading a view without a controller from the nib, use the view's awakeFromNib method.
I dont have time right this second to put some sample code, (Ill edit my question tomorrow and add some) but basically what happens is that I have a Window. It works fine usually, but if I use
[myWindow setStyleMask:NSBorderlessWindowMask]
to make it borderless, the NSTextView it contains will stop gaining focus even when you click on it: the ring will never appear, the cursor wont change and the scroll bar will remain gray.
Something else that happens when I make it borderless is that it wont update! I basically have this
[lyricsView setString:someString];
to update the string inside it. The Console marks me no errors, but the string wont appear in the Text View unless I click on it.
All of this stops happening if I remove the line setting the styleMask to Borderless. Any ideas? Suggestions? Comments? Cheers?
Thank You!
Kevin
From the documentation of NSWindow:
The NSWindow implementation returns YES if the window has a title bar or a resize bar, or NO otherwise.
So subclass your window and add this line
-(BOOL)canBecomeKeyWindow
{
return YES;
}
I have an UIButton in my View that says "STOP". When pressed, it should (stop the playback, of course, and) change its label to "RTN TO ZERO". This is straightforward:
stopButton.titleLabel.text = #"RTN TO ZERO";
However, the change appears only for a split second. It doesn't stick. I assume that the button (which gets highlighted when pressed) accepts and displays the new label, but somehow the highlight is reversed only later, restoring the button to the look it had before it was pressed, not honoring the label text change.
The button is conceived in IB, not programmatically.
I feel stupid. Can someone please point me in the right direction?
In the button handler, try this:
[stopButton setTitle:#"RTN TO ZERO" forState:UIControlStateNormal];
Instead of directly changing text property of titleLabel use setTitle:forState: method to set the title in different states. Please check the manual for the details of available states.
Swift version
myButton.setTitle("button text", for: UIControl.State.normal)
Use setAttributedTitle:for for attributed text. See here for how to make attributed strings in Swift.
Is there a way to do a general resignFirstResponder to hide the keyboard regardless of what textfield/view/etc calls it?
Reason is I have a lot of textfields on my view and don't want to have to resignFirstResponder for all textfields to hide the keyboard. Just want a general
[self resignFirstResponder].
Any ideas?
Thanks in advance
I know that this has already been marked as answered, but for those that run into this like I did you can just use the following method on the view that contains the textfields.
- (BOOL)endEditing:(BOOL)force
This method looks at the current view and its subview hierarchy for the text field that is currently the first responder. If it finds one, it asks that text field to resign as first responder. If the force parameter is set to YES, the text field is never even asked; it is forced to resign. UIView Documentation
[self.view endEditing:YES];
it will hide keyboard when we click on view.
You can dismiss the keyboard without any reference to UITextfield / UITextView with help of below code:
[[[UIApplication sharedApplication] keyWindow] endEditing:YES];
this will dismiss the keyboard globally without the reference.
hope this will help you.
The easiest way to do this is to have a method for whenever you want to dismiss the keyboard that looks like this:
-(void)dismissKeyboard {
[firstField becomeFirstResponder];
[firstField resignFirstResponder];
}
You can check these questions:
Is it possible to make the iPhone keyboard invisible / remove it without resigning first responder?
Hide Input Keyboard on iPhone Without Knowing First Responder?
In summary:
You can call becomeFirstResponder on some other thing that you choose. It could be a UIViewController or a UIView. I had a similar problem before, I needed to make my keyboard go away when I was pushing my view controller back to its caller, without knowing which textfield was the first responder. Then, on viewWillAppear of my view controller which I was returning back, I called [self becomeFirstResponder] and the keyboard of the pushed view was gone. Because this made whichever text field was it loose being the first responder
In my own app when I had more than one text field and would like to make the keyboard go away regardless which of the fields called it, I would just wrote a method and let each and every of them resignFirstResponder.
I assume that as a programmer, you should have the clear knowledge how many text fields are on your view controller and how you can access them, otherwise it'll get messed up and you app won't look good... :-P