如何将标签中一定数量的文本中的第一行设置为粗体?

发布于 2024-08-29 20:51:20 字数 127 浏览 4 评论 0原文

我有大约 400 个字符长度的字符串,其标题称为“详细信息”。在此“详细信息”中,字体大小为粗体,字体大小为 19。而所有剩余文本都从下一行开始,并且与内容一样,字体大小为 18。我如何使用 UILabel 来完成这一切? 请帮帮我...

I have about 400 character length string with a heading called Details. In this 'Details' is to be bold and of fontsize 19. While all the remaining text starts in the next line and should be of fontSize 18 like the contents. How can I do all this by using a UILabel?
Plz help me...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

灵芸 2024-09-05 20:51:20

从 SDK 3.2 开始,您无法使用现有的 UILabel 来完成此操作。您可以创建一个 NSAttributedString 来为字符串的特定部分指定特定样式(如粗体),但没有一种简单的方法来实际呈现它。这与 Max OS X 不同,Max OS X 具有 NSAttributedString(AppKitAdditions),它允许您在一行代码中绘制属性字符串。如果您想渲染它,也可以,但您必须深入研究较低级别的 API 之一(例如 Core Text)。

使用两个 UILabel 可能会更好。将第一个加粗,使第二个覆盖多行。

You can't do it with a stock UILabel as of SDK 3.2. You can create an NSAttributedString that specifies particular styles (like bold) for particular parts of the string, but there isn't a simple way to actually render it. This is unlike In Max OS X, which has NSAttributedString(AppKitAdditions), which allows you to draw an attributed string in a single line of code. If you want to render it, you can, but you'll have to delve into one of the lower level APIs (such as Core Text).

You're probably much better off using two UILabels. Make the first one bold, and make the second one cover multiple lines.

ヅ她的身影、若隐若现 2024-09-05 20:51:20

由于 UILabel 不支持属性字符串,因此您有两个选择:

  • 子类 UILabel 并覆盖 -drawRect:
  • 创建 2 个 UILabel,其中一个将显示标题,另一个将显示文本的其余部分。如果需要,您可以选择将两个标签包装到您自己的视图中。

Since UILabel does not support attributed strings, you have two options:

  • Subclass UILabel and override -drawRect:
  • Create 2 UILabels, one of which will display the heading, the other showing the rest of your text. You can choose to wrap the two labels into your own view if necessary.
帅哥哥的热头脑 2024-09-05 20:51:20

您可以使用 HTMLString 为 第一部分 的 UIWebView第二部分

You could use a UIWebView with an HTMLString of <strong>First part</strong> second part

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文