UILabel 文本一半是粗体,一半不是?
我希望 UILabel
的 text
的一半为粗体,另一半为非粗体。我该怎么做?
I want half of my UILabel
's text
to be bold and half to not be bold. How can I do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
NSAttributedString 允许在其中指定格式一个字符串,但遗憾的是,UIKit 还没有对此做任何事情。然而,有一些开源实现可以做到这一点。查看 OHAttributedLabel。
NSAttributedString allows for specification of formatting within a string, but sadly, UIKit does not yet do anything with this. However, there are a few open-source implementations that do. Check out OHAttributedLabel.
除非您子类化 UILabel 并弄乱子视图,否则您无法轻松做到这一点。最好改用两个 UILabel。在这里找到另一个线程关于它。
You can't do this easily unless you subclass UILabel and mess with the subviews. Better to use two UILabels instead. Found another thread about it here.
UILabel 有
attributedText
,它采用NSAttributedString
,它允许您自定义字符串的多个方面,包括更改字体类型和其他属性UILabel has
attributedText
which takes aNSAttributedString
which allows you to customize multiple aspects of a string including changing the font type and other attributes