https://iphonedev.wiki/index.php?title=UITableViewCellLayoutManager&feed=atom&action=historyUITableViewCellLayoutManager - Revision history2024-03-29T00:31:22ZRevision history for this page on the wikiMediaWiki 1.39.6https://iphonedev.wiki/index.php?title=UITableViewCellLayoutManager&diff=541&oldid=prevKennyTM~: Created page with 'UITableViewCellLayoutManager is a model class for styling a UITableViewCell. It is the class that powers the "style" in the {{ObjcCall|UITableViewCell| initWithStyle:reus…'2009-12-11T18:58:04Z<p>Created page with '<a href="/UITableViewCellLayoutManager" title="UITableViewCellLayoutManager">UITableViewCellLayoutManager</a> is a model class for styling a <a href="/UITableViewCell" title="UITableViewCell">UITableViewCell</a>. It is the class that powers the "style" in the {{ObjcCall|UITableViewCell| initWithStyle:reus…'</p>
<p><b>New page</b></p><div>[[UITableViewCellLayoutManager]] is a model class for styling a [[UITableViewCell]]. It is the class that powers the "style" in the {{ObjcCall|UITableViewCell| initWithStyle:reuseIdentifier:}} method. UITableViewCellLayoutManager is available since 3.0.<br />
<br />
You can set your own layout manager to a table view cell with its <tt>layoutManager</tt> property.<br />
<br />
Everything that can be done with layout manager can also be done with a subclass of UITableViewCell, which is SDK-compliant.<br />
<br />
== Predefined layout managers ==<br />
{{function signature|signature=+(UITableViewCellLayoutManager*)layoutManagerForTableViewCellStyle:(UITableViewCellStyle)cellStyle;|firmware=3.0 –}}<br />
There are 6 predefined layout managers, 5 of which can be obtained using the {{ObjcCall|UITableViewCellLayoutManager|layoutManagerForTableViewCellStyle:|ClassMethod=1}} method:<br />
{| class="wikitable"<br />
|-<br />
! Style !! Manager class<br />
|-<br />
| 0 (<tt>UITableViewCellStyleDefault</tt>) || UITableViewCellLayoutManager<br />
|-<br />
| 1 (<tt>UITableViewCellStyleValue1</tt>) || UITableViewCellLayoutManagerValue1<br />
|-<br />
| 2 (<tt>UITableViewCellStyleValue2</tt>) || UITableViewCellLayoutManagerValue2<br />
|-<br />
| 3 (<tt>UITableViewCellStyleSubtitle</tt>) || UITableViewCellLayoutManagerSubtitle<br />
|-<br />
| 1000 || UITableViewCellLayoutManagerEditable1<br />
|-<br />
| - || UIMoreListCellLayoutManager<br />
|}<br />
<br />
== Subclassing layout managers ==<br />
[[Image:UITableViewCellLayoutManagerExample.png|right|thumb|Result of the setting the layout manager defined on the left.]]<br />
Subclassed layouts usually need to override <tt>-layoutSubviewsOfCell:</tt>, <tt>-textLabelForCell:</tt>, <tt>-detailTextLabelForCell:</tt>, -<tt>-defaultTextLabelFontSizeForCell:</tt> and <tt>-defaultDetailTextLabelFontSizeForCell:</tt>. The following is an example layout manager:<br />
<source lang="objc"><br />
@interface XXLayoutManager : UITableViewCellLayoutManager {}<br />
@end<br />
@implementation XXLayoutManager<br />
-(UILabel*)detailTextLabelForCell:(UITableViewCell*)cell {<br />
UILabel* label = [self defaultLabelForCell:cell];<br />
label.textColor = [UIColor redColor];<br />
label.shadowColor = [UIColor colorWithWhite:0 alpha:0.5];<br />
label.shadowOffset = CGSizeMake(1, 1);<br />
return label;<br />
}<br />
-(CGFloat)defaultDetailTextLabelFontSizeForCell:(UITableViewCell*)cell { return [UIFont systemFontSize]; }<br />
-(void)layoutSubviewsOfCell:(UITableViewCell*)cell {<br />
[super layoutSubviewsOfCell:cell];<br />
CGRect contentBounds = cell.contentView.bounds;<br />
<br />
UIImageView* imageView = [cell _imageView:NO];<br />
if (imageView != nil) {<br />
CGRect imageFrame = imageView.frame;<br />
CGFloat leftPadding = imageFrame.origin.x + imageFrame.size.width;<br />
contentBounds.origin.x += leftPadding;<br />
contentBounds.size.width -= leftPadding;<br />
}<br />
<br />
UILabel* textLabel = [cell _textLabel:NO];<br />
if (textLabel != nil) {<br />
CGFloat fontSize = textLabel.font.pointSize;<br />
if (fontSize == 0)<br />
textLabel.font = [UIFont boldSystemFontOfSize:[self defaultTextLabelFontSizeForCell:cell]];<br />
NSString* text = textLabel.text;<br />
if (text == nil || [text length] == 0)<br />
[textLabel removeFromSuperview];<br />
else if (textLabel.superview == nil)<br />
[cell.contentView addSubview:textLabel];<br />
}<br />
<br />
UILabel* detailTextLabel = [cell _detailTextLabel:NO];<br />
CGFloat detailWidth = 0;<br />
if (detailTextLabel != nil) {<br />
UIFont* font = detailTextLabel.font;<br />
CGFloat fontSize = font.pointSize;<br />
if (fontSize == 0)<br />
detailTextLabel.font = font = [UIFont boldSystemFontOfSize:[self defaultDetailTextLabelFontSizeForCell:cell]];<br />
NSString* text = detailTextLabel.text;<br />
if (text == nil || [text length] == 0)<br />
[detailTextLabel removeFromSuperview];<br />
else {<br />
detailWidth = [text sizeWithFont:font].width;<br />
if (detailTextLabel.superview == nil)<br />
[cell.contentView addSubview:detailTextLabel];<br />
}<br />
}<br />
<br />
cell.contentView.bounds = contentBounds;<br />
const CGFloat vpad = 5, hpad = 20;<br />
textLabel.frame = CGRectMake(hpad, vpad, contentBounds.size.width-detailWidth-3*hpad, contentBounds.size.height-2*vpad);<br />
detailTextLabel.frame = CGRectMake(contentBounds.size.width-detailWidth-hpad, vpad, detailWidth, contentBounds.size.height-2*vpad);<br />
}<br />
@end<br />
</source><br />
<br />
== References ==<br />
{{IPFHeader|UIKit}}</div>KennyTM~