How to get the same UITableViewCell layout as in the Address Book app?
I currently have a custom UITableViewCell
which contains a few labels, and an image.
The "main" label is used to display people's names. Currently, I'm styling it 开发者_如何学编程in bold text.
What I'd like to do (to gain some space and readability), is to mimic the Address Book app cell style, that is: first name in light text, and family name in bold text.
Is there a way to do this using the same UILabel
? Or, should I use 2 different UILabel
s? How should I layout them, without knowing their sizes?
Thanks in advance for your assistance!
See this sample code from atebits:
http://atebits.cachefly.net/blog/FastScrolling/FastScrolling.zip
It does something similar to what you want.
You can use the built-in UITableViewCellStyleValue2. From the UITableViewCell.h header file:
UITableViewCellStyleValue2, // Right aligned label on left with blue
//text and left aligned label on right (Used in Phone/Contacts)
Pass this into your [[UITableViewCell alloc] initWithStyle:...] method.
I think it's table view cell with UITableViewCellStyleDefault style. If you'd like to use different font attributes then you need to use different labels (because there is no attributed strings yet). To calculate size of these labels you should use following method:
- (CGSize)sizeWithFont:(UIFont *)font minFontSize:(CGFloat)minFontSize actualFontSize:(CGFloat *)actualFontSize forWidth:(CGFloat)width lineBreakMode:(UILineBreakMode)lineBreakMode;
or any relevant from NSString(UIStringDrawing)
.
Also, you can use custom strings drawing instead of UILabel.
精彩评论