custom number pad - iphone

I want to create my own number pad to appear after user focus the textfield, so I have two question about it?
1.I use "Interface Builder to add a textfield in my view and select the "Number Pad" as the default pad for user to input number, so when I click the textfield, the number pad appear automaticlly, how can I stop it appear the number pad? because I want to show my number pad.
2.If I custom a view with number button inside it, how can I detect the event when I click the textfield? and whether after I detect the event I add a subview to show my custom number pad or not?
thanks

If you are creating a custom number pad (I assume this means a view with a grid of buttons), don't bother using a UITextField; there is no easy way to hide the native keyboard and, for all that trouble, there is nothing useful that the text field gives you.
I recommend creating a custom UIControl subclass. You can detect a touch inside the view and show your custom keypad that way. The documentation explains this pretty well.

I have a partial answer but not an ideal one, and I haven't tried this myself. Take a look at the documentation for the UITextFieldDelegate protocol.
You could have your controller set textField.delegate = self, then have it implement textFieldShouldBeginEditing to show your specialized keyboard somehow and then return NO so that it doesn't go into edit mode. When you tell your special keyboard to show itself, pass it a reference to the text field so it knows where to insert characters. The problem is that this probably won't show a cursor and won't let the user move the cursor to insert characters, etc.
So really this a bit ugly, but it may be sufficient. AFAIK there is no good way to do this :(

Related

Can I customize keyboard layout for apple tv?

I want to have a custom keyboard (without full-screen keyboard) instead of default keyboard in my apple tv app?
If possible, what are the approaches should I follow?
Any suggestions appreciated.
The SearchTemplate is the only keyboard available for TVML, and there isn't a whole lot you can do with it.
But with TVML, there's 2 ways you can do redo the keyboard
1) using section with lockup and some TVJS, to create your own keyboard. Each lockup can be a character and onclick, can trigger tvjs to record and display the character into a label. Should be relative easy to implement, specially if you are only dealing with a small set of characters, like numbers.
2) custom element, as described in the docs, you can use native code to define any element and.. you can make your own keyboard that way.
=-=-=-=-=-=
Update
Somehow I missed the form template. This template included a keyboard too. And, you can *customize this keyboard!
The textField element provides a field for users to enter text, which also accepts the keyboardType attribute for selecting the type of keyboard to display. It even has support for number and URL inputs.
(*basic customization lol)

Should I make separate UIViewController just because a single row is different in layout

I am a very basic SWIFT Xcode programmer. I make small apps.
For last 2 days, I am stuck at a very simple thing and I am sure with your guidance I can quickly make a decision.
I have a UIViewController class as well as an xib
In the layout I have 4 textfields
Now based on a user setting (in another frame user make a choice), I will either have to show 4 textfields ** OR ** 3 textfields and a UISwitch.
Long story short, if user select one option he should see UISwitch and 3 textfields or else 4 textfield. The labels's text also change.
To my limited knowledge, I will make another UIViewController, another XIB file and if user selection allows I will segue to the new UIViewController.
But all this looks so redundant. How do you smart people do this thing?
(Edit)
I use size classes in my layout as well as constraints in the visual editor for positioning of elements on the layout. If I change things programmatically, which is one option, how will I manage the layout ?
Please advise.
Show me the right path please.
When user select first option based on action show or hide the text field or switches, like when user select first option only show three text field and one UIswitch hide fourth text field.
And programatically change text field hint value and also set NSString Tag="first" so that when you want that value at the time of submit button you can apply if condition to tag and on that basis you can get your desired output on each selection.

Accessibility Focus

Working with Accessibility
While VoiceOver reads the elements in the application in an order,Is there anyway to shift the focus between the elements?
I tried working with "nextResponder",but it is not working.
As of iOS 6, you can set the focus to a specific element with a UIAccessibilityLayoutChangedNotification, passing the element
UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification, firstBottom);
but if you're trying to completely change the “tab order” I don’t know of a way to do it.
This is a shot in the dark, but have you tried changing the accessibilityLabel or accessibilityHint in accordance when you want the order to change? If you can trick the VoiceOver to believe the text has changed, I would expect that it would change focus to it appropriately.
The timing would be the hard part, since it doesn't appear there are any delegate callbacks for when VoiceOver is crawling your view, so you may have to estimate the time to pass before trying to update the accessibility hint/value.
My last thought would be to mark the UIView that you want to bring attention to with the UIAccessibilityTraitUpdatesFrequently accessibility trait. That might be the closest you can get without tapping into hidden Apple libraries.
Check out this post for how to handle special ordering of elements for voice over. I just used this approach in the app I'm working on.
I tried UIAccessibilityPostNotification(UIAccessibilityScreenChangedNotification, elementName); to change the focus on a different element. The behavior was that the focus got shifted to new element, but Voice Over would first announce the page title and then the accessible label value of the new element.
Customise Accessibility for a View:
You can customise the order(in which voice over should traverse the screen elements) by overriding accessibilityElements property of parent view in below manner.
self.accessibilityElements = [childView1, childView2, childView3]
With that voice over will follow the sequence like childView1 -> childView2 -> childView3.
Changing Accessibility focus to other element programatically:
At any time you can shift the focus to another element by using below code.
UIAccessibility.post(notification: .layoutChanged, argument: childView2)
With above code, voice over focus would be shifted to childView2 and then will follow the same sequence defined by accessibilityElements i.e. childView2 -> childView3 -> childView1... and so on
Customising Accessibility Order for Complex Views:
You can customise it further and If a view has multiple child views with further grand children views, then you can achieve accessibility order by defining accessibilityElements of main parent view by using accessibilityElements of all child views.
For example, for below view hierarchy, we have
View Controller Example
To define custom order of accessibility elements for such views, we can define in below manner.
var customElements = childView1.accessibilityElements
customElements.append(contentsOf: childView2.accessibilityElements)
customElements.append(contentsOf: childView3.accessibilityElements)
parentView.accessibilityElements = customElements

UIActionSheet truncates long strings! Alternatives?

I have a UIActionSheet which gives the user a few standard choices. The text on the buttons, however, does not cleverly scale down like a text field though when there's too much-- it just truncates with an ellipsis.
I need to say a little more in on of my action sheet buttons than there's room for. I don't see any way of changing the action sheet's behavior, unfortunately. Any thoughts on alternatives?
Thanks!
You could put some of the descriptive text in the UIActionSheet's title property, and then give just the verb or something concise in the button titles.
One alternative is: you might want to create a full-screen view that you show with presentModalViewController:animated:, where you have more space to show the text.
A third alternative is to create a UIView that animates up with UIButtons that you can customize, but doesn't fill the entire screen. I do that with some of my apps where the Settings are in a tab that slides up but doesn't need to cover the entire screen.

Change the keyboard in UITextField with animation

I have a table with several textFields in several cells, each with different input keyboards (numeric for phone number, standard for name, etc.).
When I change the editing text field by selecting one when other is editing, I want the first text field to hide the keyboard (the one which is being used) and only then the new keyboard to appear.
But putting [textField resignFirstResponder] doesn't solve my problem (the new one appears without the other disappearing, making the animation unnoticeable).
I tried to put the thread sleeping, but it didn't work as I wished.
Is there a way to have this animation?
Thanks a lot.