简体   繁体   English

在Interface Builder中更改UITextView中单个单词的字体

[英]Change font of individual words in UITextView in Interface Builder

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. 我最近在另一个程序上苦苦挣扎了3个小时,这个问题非常简单,以至于互联网上还没有人遇到这个问题。

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. 无论如何,我要执行的操作是在“界面”构建器中的程序中添加UITextView,复制并粘贴文本块,然后将适当的单词加粗,将适当的单词设为斜体。 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. 我知道,如果我选择该字段并按cmd t,则可以更改整个块的文本,但是,我似乎无法找到只更改某些单词的方法。 I know it is possible because I have apps on my iPod Touch that do EXACTLY this. 我知道这是有可能的,因为我的iPod Touch上确实有可以执行此操作的应用程序。

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. 这不是一个愚蠢的问题: UITextView仅支持一种字体,样式,大小和颜色。

The easiest solution -- though it may or may not be the best -- is to use a UIWebView with HTML-styled text in it. 最简单的解决方案(尽管不一定是最好的)是使用带有HTML样式的文本的UIWebView A web view seems like a lot of overhead for such a little thing, and it probably is. Web视图似乎要花很多时间来处理这样的小事情,而且可能确实如此。

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. 但是,直到8个月前,它才是唯一的解决方案(嗯,我相信您以前也可以使用Quartz / Core Graphics,但我很少看到它),即使那时它也只能在iPad上使用。 With iOS 3.2 or greater you can use Core Text on all iOS devices. 使用iOS 3.2或更高版本,您可以在所有iOS设备上使用Core Text。 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. 我实际上不知道Core Text的开销与UIWebView相比如何。

也许不是在提问时,但是至少现在,可以通过在属性检查器中将文本设置为“从普通属性”来实现

I don't think what you want is possible with a UITextView . 我认为UITextView不可能实现您想要的一切。 Maybe try CATextLayer 's string property which can be set to an NSAttributedString . 也许尝试一下可以将CATextLayerstring属性设置为NSAttributedString

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM