Xcode UITextView Change textcolor of specified word - iphone

I would like to change the font color of a certain word inside a UITextView.
if([text1.text isEqualToString:#"value"]) {
}
That's what I have right now, and I want the word value to change font color, any ideas? Sorry if it's simple but I'm still learning ;)

It's not possible, sorry.
from UITextView Class Reference
This class does not support multiple
styles for text. The font, color, and
text alignment attributes you specify
always apply to the entire contents of
the text view. To display more complex
styling in your application, you need
to use a UIWebView object and render
your content using HTML.

Related

Difference between UIWebView Fontsize and UItextView Fontsize

Can any one tell me what is the major difference between UIWebView's font size property and UITextView's FontSize property??
Both are different, As UIWebView's Fontsize is very bigger then UITextView's font size, through both are 15..
Please tell me, What is the difference?
Thanks in advance..
Following is working properly.
<html><body style="margin-top:0px; margin-left:0px"><marquee behavior="alternate" style="font-family:verdana;font-size:10px; color:red;">Test</marquee></font></body></html>
although both are rendering HTML but main difference is,
UIWebView giving u the HTML view its font size denpend ViewPort,
where as the UITextView can control its font size.
According to the official Objective C website:
"This class does not support multiple styles for text. The font, color, and text alignment attributes you specify always apply to the entire contents of the text view. To display more complex styling in your application, you need to use a UIWebView object and render your content using HTML."
How I understood it: on a UIVewView you can use as text HTML tags, in UITextView it will be displayed as a plain text. The UIWebView's font's size depends from the ViewPort, and you have no direct access to it, as well as the UITextView has properties for the font size setup.

iPhone iOS5 How can I present a font type, size, color and alignment widget to the user?

I have a few UITextFields and I would like the user to be able to change the font's appearance within those fields.
Right now I have a UIToolbar with 5 buttons used for font controls. One for font name, one for size, one for color and one for alignment.
To change font, I display a picker with the fonts family names, letting the user pick default font for that family.
For the font color, I display another toolbar with a font size slider
For font color, I display an open source color picker
For font alignment, I display a button that cycles through the left/center/right alignment.
Finally there's a close button that hides the toolbar.
Currently all of my code is in one controller, but I would like to have it refactored into a separate, reusable class.
Since I'll be rewriting code, are there any open source font controls like I'm describing above? Maybe I can just plug in something that's already made into my project?
Thank you!
It wouldn't be very hard at all. Instead of pickers use a scroll view with buttons and labels above them using the font. As for size you could do the same!
This would be easy in Xcode 4, not so sure in 3.X.X
I found that the attributed string example by apple does have a table view-like font controller that includes a preview of what fonts look like. I think extending that controller may be the easiest thing to do:
http://developer.apple.com/library/ios/#samplecode/CoreTextPageViewer/Introduction/Intro.html

how to change the color of the first text in UITextView

is there a way where we can change the color of the first text in UITextView and the rest of the text will in default color which is black
If you are asking if you can change the color of a word or sentence of a UITextView but not the entire content, the answer is no unfortunately.
Check this answer here, Change font of individual words in UITextView in Interface Builder
It is possible to use a UIWebView to render the text in the manner you are asking. You could also draw it yourself using CoreText, but that would be quite a pain.
Hope this helps,
Matt

Changing font formattings of selected word/line in a UITextView

Has anyone tried to change the font formatting(bold/italic/color) of a selected word or sentence in a UITextView, like a text editor application? I have been trying to do this but it seems formatting is applied only to the whole text, not on individual words or sentences.
you can change any specific word font, style and size also,
Make UITextView text to "Attributed", by default it was "Plain"
and then you can perform edition on selected text.
UITextView cannot style text fragments. Styles, colors and fonts are applied to the entire text. You may wish to use a UIWebView or Core Text to render your text instead.

How do I apply CSS to style the text in a UILabel?

I would like to be able to style the text in a UILabel using CSS. I know that you can use a UIWebView to load HTML to be formatted for display using
[webview loadHTMLString:myText baseURL:nil];
but I would like to simply style just a UILabel without relying on UIWebView. How can I do this?
Look at the open source project called FontLabel at http://wiki.github.com/zynga/FontLabel.
Although it won't let you apply a CSS file to a UILabel, it does provide a subclass of UILabel that can use custom fonts and styling.
Of course you can also use the standard properties of UILabel like color, textAlignment, etc.
Since css file structure is very easy you could create a simple css parser that searches a certain id or class. Then get the font size, name, style and other attributes and instead of using UILabel you maybe want use CATextLayer because text is much more customizable (colors, font, size, style, and even more than one fonts in a single line)
But I wonder why do you need a UILabel and not UIWebView?
Hope it helps