Let me apologize in advanced if this question sounds stupid it's so incredibly simple. I struggled for 3 hours with another program recently with a problem that was so simple that no one on the internet had even had the problem yet.
Anyhow, what I want to do is add a UITextView to my program in Interface builder, copy and paste a block of text, then make the appropriate words bold, and the appropriate words italic. That's all. I know that if I select the field and hit cmd t, I can change the text of the entire block, however, I can't seem to find a way to only change certain开发者_开发问答 words. I know it is possible because I have apps on my iPod Touch that do EXACTLY this.
Anyhow, I'm hoping there's a way to do this in interface builder since doing it programatically (on the particular project I'm working on) could get very messy very fast.
Thank you in advance, and forgive me if I make you rofl or something since I'm so new to all this apple stuff...
It's not a stupid question: UITextView
s only support a single font, style, size, and color.
The easiest solution -- though it may or may not be the best -- is to use a UIWebView
with HTML-styled text in it. A web view seems like a lot of overhead for such a little thing, and it probably is.
Nonetheless, until 8 months ago it was just about the only solution (well, I believe you could also use Quartz/Core Graphics previously, but I rarely saw it), and even then it was only on the iPad. With iOS 3.2 or greater you can use Core Text on all iOS devices. Unfortunately there's quite a lot to learn, but it's definitely doable.
I actually don't know how the overhead of Core Text compares to a UIWebView.
Maybe not at the time of questioning, but at least now this is possible by setting the text to Attributed from Plain, in the Attribute Inspector
I don't think what you want is possible with a UITextView. Maybe try CATextLayer's string
property which can be set to an NSAttributedString.
精彩评论