I'd like to be able to show a UITextView that has multi-colored hyperlinks (ie, some hyperlinks red, some blue, some green, etc.)
No matter what I set NSForegroundColorAttributeName to for the given range of the hyperlink it always seems to get overwritten by whatever is specified in myTextView.linkTextAttributes.
Is there a way I can disable the linkTextAttributes functionality or override its styles on a per-range basis?
You can find my full tutorial about multiple hyperlink colors here: https://octodev.net/changing-uitextview-hyperlink-color/
Tutorial contains implementation in both languages: Swift and Objective-C.
Would be more than glad to answer all your questions.
Related
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.
I am trying to create a custom keyboard using the app keyboard extension. I am happy with the layout but the output is depended on the UITextField's font.
Is there a way to force a different font (use special characters?) while using the keyboard ?
Thank you
It depends.
Text field (or any other view that draws text) uses 2 informations on how to show some text. One is the sequence of characters called String and the other one is how the string should be represented. The second one is then split it things like fonts, colors, line height, line breaking and wrapping...
So the keyboard alone is not enough to for instance present a certain part of word using different fonts. You need at least a bit of access to the item that represents the text. So if you have no access to your text field then the answer is; No, you can not fore a different font when using different keyboard.
If you do have the access then the answer should lie in NSAttributedString. It is a string you can assign to most items under attributedText. This class wraps your raw string and can add many properties to parts of text you want to change. That includes using a different font.
Another approach would be using HTML tags. Again you will need to process this using for instance NSAttributedString or display it with another element like web view.
I would try it with using NSAttributedString. Hook up to delegate and implement textField(: shouldChangeCharactersIn: replacementString:. The implementation itself may still not be easy though.
UIBarButtonItemStyle can be:
Bordered
Done
Plain
Even reading the documentation I do not know what is the difference and when do I use which?
If you can read Apple documentation then you can find its answer. As par doc this Border,plain and Done is a Specifies the style of a item.
Plain (UIBarButtonItemStylePlain)
Glows when tapped. The default item style.
Border (UIBarButtonItemStyleBordered)
A simple button style with a border.
Done (UIBarButtonItemStyleDone)
The style for a done button—for example, a button that completes some task and returns to the previous view.
For testing you can create a demo project in Xcode and set different different style and you can understand the difference.
Please look at the below image, Red Color Texts are two different strings and Ash color String are another string. I concatenate those strings into one String and i assigned that string into UILabel.
i used NSMutableAttributedString for applying colors and Font styles to NSString
Now i need to show two separate Links on the Red Color Strings " SIVASAGAR" and "THE ORDER:1886", when user clicks on that links, it redirects to different views.
Is it possible to achieve this type of scenario using UIButton or STTweetlabel or something else?
NOTE: All the names ,i mean Red Color Strings Positions(X and Y values) will change Dynamically according to requirement.
I think you should use UITextView and add:
[attributedText addAttribute:NSLinkAttributeName value:#"yourCustomSchemeUrl://" range:linkRange];
and implement Custom URL Scheme
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.