UITableViewCell:标签内带有样式线的文本

发布于 2024-09-08 15:23:26 字数 728 浏览 1 评论 0原文

我的目的是显示一个 UITableView ,其中单元格的样式如下:

TextA - 大字体的粗体文本

TextB - 小字体的粗体文本

TextC - 与 TextB 字体大小相同的普通文本

UITableViewCellStyleSubtitle 样式几乎完美,我可以将 TextA 设置为 textLabel 和包含 TextB 和 TextC 的字符串作为 detailTextLabel,其中 numberOfLines 等于 2。但是这样 TextB 和 TextC 具有相同的字体粗细。

我已经看到现在支持 NSAttributedString,这很好,因为我的应用程序在任何情况下都只兼容 iOS 4,并且我尝试使用 CoreText API 编写样式标签。 但问题是 detailTextLabel 是一个只读属性。

唯一想到的是将 CoreText 中编写的自定义标签作为子视图(带有 addSubview 消息)添加到 UITableViewCell 对象的 contentView 中。

或者,我可以创建两个 UILabel 并将它们添加为单元格的子视图。

有没有比添加为子视图更优雅的方法?

my purpose is to display a UITableView with cells with a style like:

TextA - bold text with a big font size

TextB - bold text with a small font size

TextC - normal text with the same font size of TextB

The UITableViewCellStyleSubtitle style is almost perfect, I could set TextA as textLabel and a string that contains TextB and TextC as detailTextLabel with numberOfLines equal to 2. But in this way TextB and TextC have the same font-weight.

I've seen that NSAttributedString is now supported, it's good because my application will be in any case only iOS 4 compliant and I've tried to code a styled label with CoreText API.
But the problem is that detailTextLabel is a readonly property.

The only thing that came to mind is to add the custom label written in CoreText as subview (with addSubview message) to the contentView of UITableViewCell objects.

Alternately I could create two UILabel and add them as subviews of cells.

Is there a more elegant way than add as subviews?

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

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

发布评论

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

评论(2

夢归不見 2024-09-15 15:23:26

无论如何,使用您自己的视图是使其正确布局的最简单方法。

In any case, using your own views is the easiest way to get it to lay out correctly.

嗼ふ静 2024-09-15 15:23:26

在这一点上我同意 tc 的观点。在必须将自定义标签添加到 Apple 单元格选项之一之前,或者您可以简单地创建自己的自定义表格视图单元格之前,您只能使用 Apple 提供的表格单元格。我建议找到一个有关创建自己的表视图单元格的教程,然后从那里开始。出版商 Apress 有一本关于 iPhone 3 的入门书,它在我遇到这种情况时对我有帮助。

I agree with tc on this one. You can only go so far with the Apple provided table cells before you either have to add custom labels to one of the Apple cell options or you can simply create your own custom table view cell. I would recommend finding a tutorial on creating your own table view cell and go from there. The publisher Apress has a befinning iPhone 3 book which helped me in this exact situation.

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