简体   繁体   English

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

[英]UITableViewCell: Text with styled lines inside label

my purpose is to display a UITableView with cells with a style like: 我的目的是显示带有样式的单元格的UITableView

TextA - bold text with a big font size TextA-具有大字体大小的粗体文本

TextB - bold text with a small font size TextB-字体较小的粗体文本

TextC - normal text with the same font size of TextB TextC-具有与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. UITableViewCellStyleSubtitle风格几乎是完美的,我可以设置为TEXTA textLabel和包含TEXTB和TextC作为字符串detailTextLabelnumberOfLines等于2。但这种方式TEXTB和TextC具有相同的字体重量。

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. 我已经看到现在支持NSAttributedString ,这很好,因为我的应用程序无论如何都仅兼容iOS 4,并且我尝试使用CoreText API编写样式标签。 But the problem is that detailTextLabel is a readonly property. 但是问题是detailTextLabel是只读属性。

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. 唯一想到的是将以CoreText形式编写的自定义标签作为子视图(带有addSubview消息)添加到UITableViewCell对象的contentView中。

Alternately I could create two UILabel and add them as subviews of cells. 或者,我可以创建两个UILabel并将它们添加为单元格的子视图。

Is there a more elegant way than add as subviews? 有没有比添加为子视图更优雅的方法?

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

I agree with tc on this one. 我同意tc在这一方面的观点。 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. 您必须先使用Apple提供的表格单元,然后才能将自定义标签添加到Apple单元选项之一,或者您可以简单地创建自己的自定义表格视图单元。 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. 出版商Apress拥有一本精采的iPhone 3书,在这种情况下对我有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM