Text selected without showing the pins - ios

Is there a way to programmatically select a text without showing the pins at the beginning and at the end of the selected text?
Example:

Although you should be more precise, I presume you just want to highlight some parts of the text with a background color. Therefore you can use NSAttributedString.
You can look up how to create an attributed String here and how to use background color on it here.

Related

Array item completion in a UITextView

I'm trying to accomplish an autocomplete of my own for matching array items while typing. So, I already have the logic done for matching what's being typed with what's in the array, but my question is related to displaying the proposed correction in the UITextView like this screenshot
I was trying by splitting the text in the textview and replacing the last word into attributed strings, but that makes the proposed correction part of the actual contents. Any ideas of how this is accomplished in this app?
What you currently do is good , when you set the text of the textView to attributed string make bool flag say it's name is textEdited = true with a string part that the user types say it's name userStr , when textView change method is triggered check that bool and according to it make the search if it's true proceed search with userStr if it's not proceed search with whole textView text , don't forget to make textEdited= false after every zero suggested result
Edit: regarding the cursor put a label under the textfield with the same font as the textView and make it's background darkGray , also make background of the textview transparent and every attributed string assign it to the label so plus part of the label will be shown and cursor will be as it is in the textView

How do I re-use a color value throughout a storyboard

I am using storyboard to lay out my iOS app. I want to re-use some colors, and I don't want to re-enter the same hex string multiple times. What is the best way to do this?
You can drag the current color in the color picker (from the bottom left) to the list of swatches as in the screenshot:
You can also use the dropdown for picking a color to use a recent color. The list of recently used colors looks like it keeps 24 of them.

Adding Image And title both to UIsegmentControl IOS

Is there a way so that you can set both image and title of UISegmentControl simultaneously, so that image appear next to the title , just like image appear next to title in UIButton.
I am trying but if I set image of Selected segment of UISegmentControl then title disappears and if I set title of Selected segment of UISegmentControl then Image disappears, I want to set both at a time.
The official documentation for -setImage:forSegmentAtIndex: says
A segment can only have an image or a title; it can’t have both. There is no default image.
So, no, there is no way to do what you want using the image and title properties.
However, there are a few options to accomplish the objective in different ways.
if you are going to use the same image for each segment, you could use the appearance methods to set the background and then use the method -setContentOffset:forSegmentAtIndex: to move the title to the side of the background image.
you could create an image that had both the icon and the text in it. This is less than ideal as a change to the text requires exporting of the entire asset again. But is an option.
the least ideal would be to fake a segmented control using buttons that you write the code for to handle state changes. There may even be some open source options that do just that, so feel free to search for them.

iOS: URL link in UITextField with different text

I want to insert a URL hyperlink into a UITextField that has different display text.
This is super easy in html:
Go To Google
How can I do this in iOS?
You can change the text style inside your UITextField via an attributed string sent to the text field's "attributedText" property.
However, what I suspect you really want to do is have a link that's clickable. I would recommend using a UIButton with a custom type (i.e. no border) and you can set the color and the underline style.
But like Evan said, if you have multiple lines of text, it may be smarter to use a UITextField where you set "editable" to NO and turn on the LINK traits (both of these you can do from the object inspector in Xcode).
Alright, so here's what I did to get what I wanted. I used UIWebView, and simply linked it to an html page in the project that has the text, and hyperlink at the bottom with different text displayed.
Answer is here :
If you want it as clickable Hyperlink,
NSString *string = #"Go To Google";
You need to add "BACKWARD SLASH" before ". That's it.

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.

Resources