Styling text in a SearchBar / TextField iOS Swift - ios

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.

Related

Interact with input fields like textfield text view and button action in webview using objective c

I am looking for some solution so i need to first know that is this possible that using objective c in Xcode can we interact in quite extensive and deep level, like adding some text in textfield and textview and change label colors and interact with button actions ?
I googled but not able to find my desired solution

Output specific images when user taps the keyboard

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

Cursor issue while creating Custom keyboard with UIView

My requirement was to make a application specific keyboard i.e with a different theme and different key contents as compared to the default keyboard. But the way Apple states to implement keyboard requires user effort to add it through Settings->General->Keyboard which I don't want.
So, for that I tried to implement it using a UIView and making it the inputView for UITextView and it is working perfectly fine except for one issue. I added a functionality to add a linebreak in the textView. For that the code I used is
textView.text = "\(textView.text)\n"
Now, whenever I add a linebreak through keyboard, line is changed, but a new cursor appears to blink above the old cursor. I don't know how to get rid of that.
To explain the problem in a better way, here's a GIF image of the issue.
Please help.

shouldChangeTextInRange:replacementText: not being called?

I have a custom text view I made using CoreText which implements UITextInput to handle multi stage input on Japanese and Chinese keyboards. I'm trying to limit the number of characters that can be typed into the text view using shouldChangeTextInRange:replacementText: and I'm noticing that it's only called when a key on the keyboard is pushed, but not when a button on the thing above the keyboard which offers replacement suggestions is pushed (example below).
Does anyone know why this is and if there are any similar methods I can implement that will be called when a suggestion above the keyboard is pushed (so I can block them from being set as marked text)?

IOS 8:custom Keyboard with undo and redo button

I have developed an IOS 8 custom keyboard. I want to give it "undo" and "redo" functionality, like the default system keyboard. I have tried it in different ways but was unable to find a good solution.
We can interact with a Text Input Object textDocumentProxy with the methods
insertText
deleteBackward
documentContextAfterInput
ocumentContextBeforeInput
But I was unable to find any way of implementing "undo" and "redo" functionality.
I think we can NOT implement these function (undo,redo)
According to https://developer.apple.com/library/ios/documentation/General/Conceptual/ExtensibilityPG/Keyboard.html
Because a custom keyboard can draw only within the primary view of its
UIInputViewController object, it cannot select text. Text selection is
under the control of the app that is using the keyboard. If that app
provides an editing menu interface (such as for Cut, Copy, and Paste),
the keyboard has no access to it. A custom keyboard cannot offer
inline autocorrection controls near the insertion point.
I think there are many case that content of textfield changed and you can not know when it changed, how it changed. If we can not know, we can not know to undo to where too. I think so.
I'm developing Custom keyboard extension like you and I have many problems. (eg: how can we know the current cursor to get current text selection...)
My question: Current text selection in CustomKeyBoardExtension (hope somebody know)

Resources