Best way to disable UITextField "up" and "down" arrows - swift

My ViewController has two UITextFields, so by default the keyboard toolbar has these ^ and v buttons. I don't want the user to be able to switch between the textfields with these buttons so i'd like to hide them if possible. I've tried disabling the inactive textfield but this messes with the firstResponder methods so if possible I'd like a different solution. Is there any way to just hide these buttons from the default toolbar?
]1

You could try to set an empty inputAccessoryView of this textField. Or simply:
myTextView.inputAccessoryView = nil
to remove the whole accessoryView.

Related

Adding Textfields to scroll view programmatically?

I am trying to add a textfield to a scroll view and outlet collection on button press, how am i to do this?
Can't seem to find my answer elsewhere.
You could just add it in the beginning, have it hidden, and bring it forward on the button press by either changing the .isHidden attribute or changing .alpha.
If you want to reposition other elements in the view when it's unhidden, you can add layout constraint outlets and activate new ones each time the button is pressed.

disable tableview with all elements

I working with swift 4 for macOS and I have a NSButton, which should disable my NSTableView with all elements (textfields, buttons, ...)
In the IBAction of my button I have this code lines:
myTableView.deselectAll(nil)
myTableView.isEnabled = false
This works good, but I found a little "bug".
If I select a textfield of my tableview (edit mode on)
and press after that my button, the tableview will be disabled and all selected rows will unselect, but I can edit the content of my textfield without a problem, because the "edit mode" is still on.
Must I disable all my textfields in the tableview manually or is there an elegant trick?
You can make NSTextField lose responder with
view.window?.makeFirstResponder(view.window)
This should do the trick.

How to add keyboard in action sheet

Is it possible add keyboard in action sheet?
If yes, how can I do? ... I would like to disable the background.
Thanks, Luigi.
I think UIKeyBoard can not be added in ActionSheet but you achieve your goal but handling keyboard notifications...add the Keyboard will appear and will disappear notifications in your controller...
on keyboard will appear add a subview of frame same as the parent view frame..and set its alpha 0.5...it will look like An ActionSheet is appearing and the background will automatically be disabled and on keyboard disappear remove that view from superview...you can add tap Gesture in the view you are adding..Hope so it will be answer of your question.
You can add different controls to action sheets, like pickers and text views. However, as mentioned you can't add a keyboard.
If you want to customize what is shown when the keyboard is shown, you can slide controls with the keyboard, to make it look like they are part of the keyboard.
Alternatively you could create your own keyboard using buttons etc.

Adding smilies in Custom Keyboard

I want to add the smilies in the keyboard for text to add the comment like :P and <3 and if I did so to create the custom keyboard, will Apple reject my application?
You can add simple UIView with buttons above the keyboard, and show this view when keyboard appears. By pressing buttons just insert corresponding smiles to text.
if you are using something like UITextField, you can simply create a UIView with buttons like ":P",and assign this view to UITextField's inputAccessoryView property.

How can I show a UIDatePicker instead of a keyboard when a user selects a UITextField?

I have a nice clean UI within a table view which has a few text fields for the user to fill out. One of the fields is for the user's birthday.
I'd like to have it so that when the user selects the birthday field, a view containing a UIDatePicker would come up as, just like the different keyboards do when selecting a text field.
Can this be done? I would have to prevent the text field from being the first responder (to avoid having the keyboard come up) and I would have to animate the view sliding up if no keyboard was showing before.
Would presenting the view modally be an option? If so how would I go about doing it? From the documentation it seems that modal views still take up the whole screen, I just want to use the lower 216 pixels (height of the keyboard and UIDatePicker).
Any one have any tips on how to go about doing this?
Old question but the correct way to do this these days would be to set the UITextField's inputView to a picker you created somewhere. Something like this:
UIPickerView *myPicker = [[UIPickerView alloc] init];
// set picker frame, options, etc...
// N.B. origin for the picker's frame should be 0,0
[myTextField setInputView:myPicker];
When you go to edit a UITextField, iOS really just displays whatever view is at textField.inputView which by default is the keyboard, you can make it anything you want as long as it's a subclass of UIView.
Regarding animation, take a look at DateCell sample application -
http://developer.apple.com/library/ios/#samplecode/DateCell/Introduction/Intro.html
And in any case, the proper way to do this is set UITextField's inputView to show the picker instead of the keyboard. That's what it's meant to do. More on that here:
How can I present a picker view just like the keyboard does?
Cheers,
Oded.
I would implement this by just animating a view containing the UIDatePicker, a Done, and Cancel button) up from the bottom of the screen. Using CoreAnimation, this should be pretty easy.
Why are you using a text field if you don't want to accept user input from a keyboard? Instead use a UILabel subclass (where you override the touchesBegan/Ended:withEvent: set of methods to show the UIDatePicker) or a UIButton (where your action is a method which slides up the UIDatePicker).