开发者

UITableViewCell: Text with styled lines inside label

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?


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜