How to format a text like bold/italic in UITextField in Swift iOS? - ios

Here consider this image. I have taken a toolbar with icons for text formatting. After selecting that sentence if I hit B (bold) it should be bold. Even I need that too if I select bold then further text to be show as bold. Consider this textbox UITextField. Incase you have some good reference like github you are welcome. I have already spend two days in a row in SO but not get any proper solution. One bold function is enough for me.

Related

is there any way to Underline some text of UILabel and make it Clickable?

I have following text in UILabel. I want to underline both text. and give them click event and open related link.
I Agree to the Terms & Conditions and Hotel Booking and Cancellation Policies
but problem is I couldn't give separate click event for both underlined text.
What is the best way to do that?
I know one option give separate label for all four string. but it is harder to maintain position of all that label for different sizes
Appreciate for help!!!!
take a look of this library Might be it will help you: https://github.com/TTTAttributedLabel/TTTAttributedLabel
Suggest to change the UI design. A possible work around I found is add UILabel below this text label/button with text contains a number of under scores(_) and pin it with auto layout. N.B: It's never ever a good practice at all.

Multiline label with different font styles and IBActions

A perfect example of what I am trying to do is the Instagram comments.
Suppose we have a user and a list of text (the comment). I want my UIView to have the username in some font style and clickable along with text next to it and wrapping around to the next line (which is not clickable).
It might be easier to understand if you just look at this:
Notice how the username is clickable and separated from the text, but the text wraps around to the next line. How can I do this?

Entering/Clearing specific UITextfields?

My aim is to have text boxes - a set amount per level for people to guess a hidden word. I don't want the UITextfield to be tapped and then bring up the keyboard, I'd like to have a different button that brings up the keyboard - if that's possible.
If each box is a separate text field how could I go about entering text. When a user types on the standard apple keypad, how could each character be inputted into a certain text field. I'd preferably like the text to show in the box as soon as a key is tapped.
I'm also having trouble clearing certain letters. Say a user mis-spells something and doesn't realise until the keyboard has resigned as first responder, how could I make it so that a user can tap on maybe two boxes if the rest of the word is spelt right and the program clear it?
Is there any way of writing the program so that it inputs text only if the text field is empty? Continuing with the example above they switch two letters, they tap to clear, they then bring up the keypad and the next key then pressed fills the empty boxes. Not allowing the program to input text in a used text field that only contains a single character?
I'm using Cocos2d - I don't know if that makes a difference. I hope you understand what I mean, although I'm rather bad at explaining.
Thank you in advance for your time and any help :).
Instead of having a textbox that you don't want users to edit, why not use a label?
To show the keyboard, you need to have it linked to some UITextField (or similar). You could use an invisible UITextField, and then monitor the input and send the characters to the correspinding labels. Refer to this question.
To check if a textfield has anything in it:
[textField.text length] > 0, but I would use labels instead of textfields.
I dont really understand the other parts of your question.

How to highlight or change color of text within iOS?

I would like to highlight or change the color of certain words within text, like when you search for a term, you get the highlighted words within search results.
I know I can't do this with NSStrings, but How will I able accomplish this? I would like to display text in UITextView, but can do other options if I need to.
Thanks
In iOS 6 you can do it, because iOS 6 now allows UITextView (as well as UILabel, UIButton etc.) to display styled text (NSAttributedString). You color the word with NSForegroundColorAttributeName and color its background with NSBackgroundColorAttributeName and presto, there's your highlight. There are several very good WWDC 2012 videos on this topic.
The only way I can think right now will be using an UIWebView and using CSS and javascript to highlight words.
You can check this stack overflow answer fo an example of how to highlight text with jQuery and CSS.
Also you can check this example
I prefer using EgoTextView, you can change color for range of texts. Please check the code here.

Replace keywords by images in TextField

I have some textfield with text like "Click #button1, then #button2". Have you got any idea how to replace keywords by images ? I must do it in AS2 :/ I know there is htmlText in textField, but useing it I can only use one image, and image can only align left or right site.
Very advanced stuff. I can tell you there is no 'out of the box' solution like using html text fields or something similar. Especially if you want to mimic nearly html behaviour you have to code advanced routines that can : 1. recognize your keywords. You should google for tokenizers and 2. layout textfields according to occuring images and textblocks. Again, thats advanced!

Resources