如何将标签中一定数量的文本中的第一行设置为粗体?
我有大约 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
从 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 anNSAttributedString
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 hasNSAttributedString(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
UILabel
s. Make the first one bold, and make the second one cover multiple lines.由于 UILabel 不支持属性字符串,因此您有两个选择:
Since UILabel does not support attributed strings, you have two options:
您可以使用 HTMLString 为
第一部分 的 UIWebView第二部分
You could use a UIWebView with an HTMLString of
<strong>First part</strong> second part