Output specific images when user taps the keyboard - ios

I want to output a image when a user taps on the keyboard. Let's say the user taps A on the keyboard in a UITextView. Instead of outputting the normal A, I want to output the picture of an Ape.
If a user taps "S" I want to output the image of a sun. Is this possible with out having to make a customized keyboard?

Besides creating a custom keyboard yourself, there isn't really a neat method to getting an image output.
One thing you could do is program Swift to automatically recognise the letter input and display an image over or replacing the letter as a result.
To do this, assign a variable to your editable UITextView or UITextField. If you are using XCode you can do this by control-dragging the text field into your code and it will automatically create a weak var, but you can change the strength in the pop up box that appears.
Since you now have a variable, there are two options as to how you display the image. One way is rather boring and will clutter your code, but essentially involves this, which I have simplified for the purposes of demonstration:
if UITextInput == a {
// add image
}
You would have to repeat this for every letter of the alphabet.
Or you could create a dictionary in which each letter corresponds to each image, and find a way to cycle through them, depending on the user's input. Even though this is harder to program for a newbie, it makes the code much neater and quicker.
This is the link to the official Apple documentation on dictionaries:
https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/CollectionTypes.html#//apple_ref/doc/uid/TP40014097-CH8-ID113
However, since I assume you are programming an app for the younger market, I would recommend creating a custom keyboard as it will be easier in the long run.
Hope this helps,
will

Related

Styling text in a SearchBar / TextField iOS Swift

I'm working on an iOS app using swift. I have a SearchBar/Textview (i've tried with both) and want to split each search term a user types in, into a bubble similar to pinterest where the user can later press the cross to remove certain ones.
How do I start with this? I can only seem to change the background of the whole TextField instead of just for each word.
Here's a sample of what I am trying to achieve.
Here's a sample of what I am trying to achieve http://www.standingdog.com/blog/wp-content/uploads/2014/04/pinterest-guided-search-screen-shot.jpg
This is not really a formatted text. What they are doing is different. When a space/enter is typed in (and you can detect that by the UITextField delegate), you take the currently written text and create a view from it.
The structure of that view will be similar to the following:
+ view
+ label with the text
+ x (remove) button
You will then add this view to a container view. The purpose of this view is to keep the search term views in a list.
You can then assign this container view to [UITextField leftView].
Of course, then you have to handle removal, backspace etc.

Corona SDK - native textfield within scrollview?

In Corona SDK, I'm looking for an example/tutorial of something that seems like it should be incredibly basic: including a text input field within a scrollview.
I have been using widget.newScrollView() for the scrollview, and native.newTextField() for the text input field. The problem, of course, is that the "native" objects exist outside the Corona display object hierarchy, so the textfield can't be placed inside the scrollview and scrolled that way.
A comment on this Corona Labs blog post suggests the technique of using a placeholder image that looks like a textfield, with a touch listener that overlays the real textfield when the user touches it. Is that the best approach to take?
"Faking it" is a proven method of getting stuff done when programming, whether you're using Corona SDK or anything else. While it's nice not to have to jump through hoops to get something done, sometimes it's just the best way to handle it.
In this case, I think using a placeholder is probably the best way to go. You could create a function that uses display.newRect to create the frame of the fake textfield and then display.newText to put in the default and/or user-supplied text.
Something like:
local dObj = showFauxTextfield(x, y, width, height, str)
Create the rect and text according to the parameters passed in, put them into a display group, and pass that back to the calling code. You can then put that into your regular display group along with everything else.
Inside showFauxTextfield() you'll create an event handler that pops up a native.newTextField when it's touched.
It's a little extra work, but Corona typically saves you a lot of dev time anyway, so you'll probably still come out ahead. ;)
If you aren't keen on implementing the placeholder technique mentioned in this post you could always use the WidgetCandy library (http://www.x-pressive.com/WidgetCandy_Corona/). It includes a text field class that will provide similar functionality.

How to create custom keyboard like real keyboard in iOS?

I have to create custom keyboard like the real keyboard in iOS.
I need to do following like keyboard.
like that.
How can i create like that?
Please tell me , because i'm just new beginner.
Here's something that I created that might help. Just fork it on GitHub and change the Punjabi characters to Myanmar. Most of the hard work is done for you :)
https://github.com/kulpreetchilana/Custom-iOS-Keyboards
With a custom view and custom buttons. The keyboard itself is something very easy to do, you just need to place some buttons on a view and then show that view.
Your real problem will be connecting the button actions to the text field.
You would have to check for the first responder and then add to its text the value corresponding to your custom keyboard. It will be an even more difficult problem to actually "type" those weird characters from the keyboard in the text field. I am not familiar with them, are those real ASCII characters?
Anyway, you're in for quite some work. It's not something very difficult to code, requiring some complicate algorithms, but the implementation will be tricky and complex, so be careful

how do i make UIKeyInput make repeated deleteBackwards calls

Currently I am using UIKeyinput but it is only sending a single delteBackward event even when I hold down the delete key for a long time.
How can I make it send me multiple event calls when I hold delete down for a long time?
There is no easy way to have the system keyboard do auto-repeat. These leaves you with two options:
Fake it by using an overlay on the keyboard (see the comment by #pho0)
Implement a custom keyboard, install it as the inputView for your view or view controller and implement a custom protocol that supports auto-repeat.
Solution 1 works well if you only need the delete key to auto-repeat, but if you need all the keys to auto-repeat the overlay code becomes as complex as the custom keyboard option. (The overlay needs a rectangle for each key, so why not just replace the underlaying keyboard).
Solution 2 involves a certain amount of "up-front" work... One way you might do this is define a key cap class (like a physical key) and a keyboard layout class.
I have implemented both solutions in projects I have worked on, but I currently use solution 2 since I can create whatever keyboard I like. In the simple case the use need never know that it is not the system keyboard. For power users they can customize the keyboard as they see fit.
For what it is worth, I found it useful to have the keyboard class be dumb; it just communicates that a key has transitioned to being down or has transitioned to being up. An additional class above that decides what action should be taken.
In some ways, I know this is not the answer you were looking for, but I hope it helps,
IDZ
One thing I've seen people do is put a fake button on top of the keyboard button. When someone is holding down on it, have a timer remove the last letter every time it fires.
Hope this helps.

Curious Warning Message on UITextView

Has anyone run across this warning message building for the iPhone?
More importantly do you understand how to fix it?
"unsupported configuration data detection and editable"
It's seems to be the UITextView that is complaining.
Here's a screenshot.
The problem is that you have that textview set both to editable + to detect/autolink phone numbers, events, addresses, etc. a text area can either be editable and not detect/autolink text, or it can autolink text but not be editable.
Your settings for that textview should look like:
or
but not like:
I think in your scenario, the text input is only used to input text, nothing more. Then when it get's presented back, the "presenting text view" will take care of detecting the potential information... dates, events, etc.
To be more precise : in a simple app scenario, a user types in some text (let's say an event input text view - with no detection necessary at this point). Then when it get's eventually presented back to him or another user (let's say the detail view of the event), the text will be presented back in a "non-editable" text view that in turn will be able to have detections.
I know this question is a little old, but this is how I resolved it;
In Interface Builder I have Links Detection selected, and Editable Behaviour not selected.
Then, in my ViewController, I implemented the UITextView - (BOOL)textViewShouldBeginEditing:(UITextView *)textView { } delegate method and return NO.
It removed the warning and prevents the user from being able to edit the UITextView's content.

Resources