I have a UITextView that I would like be be able to change the color for. But I would like to be able to change the color only after 50 characters. I can use UITextViewDelegate methods to count the characters, but I'm not sure how to change the color after that.
For instance, when I have a 100 character phrase within the UITextView, I would like the first 50 characters to be blue, and the last 50 characters to be red.
Is this possible? Any advice on how to achieve this?
Many thanks,
Brett
It is possible, but not via native UITextView or so
read more here:
http://www.cocoanetics.com/2011/01/rich-text-editing-on-ios/
http://www.scoop.it/t/iphone-and-ipad-development/p/104023127/rtlabel-rich-text-formatting-for-ios-using-html-like-markup-coding-for-mobile
http://iphoneincubator.com/blog/windows-views/display-rich-text-using-a-uiwebview
like #Nekto said
You can set only one color for all characters in one text view, using textColor property. If you want different colors in one sequence of characters, you can use, for example, UIWebView and html tags.
Related
I have a problem with the size of my text.
When my text is too long in a WKInterfaceLabel, no problem, I just add line or I pass line at 0 to increase automatically the number of lines.
But with WKInterfacePicker, impossible to increase the number of line and I have "..." at the end of my text.
Do you have solutions to display all my text or, at least, to delete this "..." and replace it by some letters more from my text. I work with Swift.
For the second solution, I prefer have "My text" than "My te..."
Sadly, this is not possible. Apple doesn't provide any sort of way on managing that.
A possible, but rather complicated solution would be making a costume picker with labels with multiple lines and using the newly implemented WKCrownSequencer as well as the WKCrownDelegate in watchOS 3 to detect the state of the digital crown. The default picker animations might be impossible or very difficult to reproduce, but it might fix your problem.
try this set in size width = size to fit width content
Simply stated -
I want to have a scrollable text field with a paragraph of text. Some of the sentences should be bold and blue while others are red and normal, while the remainder is simple black/normal text.
Any way to alter the text attributes 'within / amongst' the text?
Thanks!
A lie for your sanity: no, you cannot
do this.
The truth (use with caution): You can
create attributed strings... using
core text (but just don't even bother
lol - its not worth it).
The compromise: Use a UIWebView and
HTML. :) Can't say fairer than that.
I have a UILabel with a dynamic string as the text property. If I always want the first word to be underlined, do I need to separate labels and then try to line them up correctly? Or could I subclass UILabel to have it do this?
Use a UIWebView and render the text as HTML.
I ended up using the textRectForBounds:limitedToNumberOfLines: to find the dynamic start point of the word (minus some x coordinate pixels), and then took away the first letter of the uilabel with stringByReplacingCharactersInRange:withString:, and then added another uilabel with the beginning letter of the original label, just with different font.
Hi I'm developing a simple writing program using UITextView to study Cocoa programming.
In UITextView, each line has different number of characters.
I tried to change fonts of UITextView, but the width of each character seems to vary. For example, l and L has different width.
Is there anyway to keep the same number of characters in each line of UITextView like emacs or just like this editing box of stackoverflow?
Thank you so much.
easiest way is to use a monospaced font like Courier New
I've been using uiLabels to put text in the cells of tableviews. I want to now use paragraph text that carriage returns to the next line instead of going out of the boundaries of the table cell. Would I do this by manipulating a uiLabel or would I use a different control all together like a text view.
Also is there any project examples out there that implement this?
Thanks,
Joe
Simplest way is to use a UILabel and set the number of lines in IB to > 1 then set the line break to "Word Wrap."
Another way is to use a UITextView, load the data and set it to 'disabled' so it can't be edited.
Finally, you can always go the UIWebView route and load it with formatted HTML, complete with line breaks, etc. Pretty heavy, but most flexible.
The simplest approach is to use a UILabel, probably. The only alternative would be to make a custom UIView subclass that draws the text directly, but that will give you marginal benefit.