如何以不同的方式格式化 UILabel 字符串中的不同字符?
我有一个 UILabel,其文本属性为动态字符串。如果我总是希望第一个单词带有下划线,我是否需要分隔标签,然后尝试将它们正确排列?或者我可以将 UILabel 子类化以使其执行此操作吗?
I have a UILabel with a dynamic string as the text property. If I always want the first word to be underlined, do I need to separate labels and then try to line them up correctly? Or could I subclass UILabel to have it do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
UIWebView
并将文本呈现为 HTML。Use a
UIWebView
and render the text as HTML.我最终使用
textRectForBounds:limitedToNumberOfLines:
来查找单词的动态起点(减去一些 x 坐标像素),然后使用stringByReplacingCharactersInRange:withString 去掉 uilabel 的第一个字母:
,然后添加另一个uilabel,其开头字母是原始标签的首字母,只是字体不同。I ended up using the
textRectForBounds:limitedToNumberOfLines:
to find the dynamic start point of the word (minus some x coordinate pixels), and then took away the first letter of the uilabel withstringByReplacingCharactersInRange:withString:
, and then added another uilabel with the beginning letter of the original label, just with different font.