如何以不同的方式格式化 UILabel 字符串中的不同字符?

发布于 2024-10-18 03:44:39 字数 100 浏览 4 评论 0原文

我有一个 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 技术交流群。

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

发布评论

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

评论(2

于我来说 2024-10-25 03:44:39

使用 UIWebView 并将文本呈现为 HTML。

Use a UIWebView and render the text as HTML.

╄→承喏 2024-10-25 03:44:39

我最终使用 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 with stringByReplacingCharactersInRange:withString:, and then added another uilabel with the beginning letter of the original label, just with different font.

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