Permalink
Browse files

fixed merge errors

  • Loading branch information...
2 parents fc16b47 + f5fb824 commit 6526d0ce1cd20f0cebdf77772ce45155098842c8 @ettore committed Dec 15, 2012
Showing with 36 additions and 13 deletions.
  1. +12 −3 CLCGCell.h
  2. +24 −10 CLCGCell.m
View
@@ -58,7 +58,7 @@
CGFloat mImgH;
CGFloat mPadding;
UIColor *mNormalColor;
- UIColor *mEmphasizedColor;
+ UIColor *mEmphasisColor;
BOOL mEmphasized;
id mContext;
}
@@ -70,7 +70,15 @@
@property(nonatomic,retain) UILabel *infoTextLabel;
@property(nonatomic,retain) UIColor *normalColor;
-/*! Designated initializer. */
+/*!
+ The designated initializer.
+ Sets up the styling of the cell, according to the given width and height of
+ the image and padding.
+ The padding value adds whitespace to all sides of the cell (i.e. left, right,
+ up, down), on the right side of the image and the left side of the accessory
+ view (if you use it) and between the textLabel and detailTextLabel.
+ To use no image, simply construct a cell with image width and height set to 0.
+ */
-(id)initWithImageWidth:(CGFloat)w
height:(CGFloat)h
padding:(CGFloat)padding
@@ -114,11 +122,12 @@
/*!
@abstract The max width accounted during layout calculations for the
accessory view or discolosure arrow.
- @discussion By default, CLCGCell does not use a true accessory view. Rather,
+ @discussion By default, CLCGCell does not use a true accessory view; rather,
it employs the default UITableViewCellAccessoryDisclosureIndicator type.
If you use actual custom views for your accessory element, you should
probably create a subclass and override this method with actual
measurements.
+ If you don't use any accessory item, override this method and return 0.
@return A constant value that should account for the size of a default
accessory type.
*/
View
@@ -84,7 +84,7 @@ -(void)dealloc
CLCG_REL(mImgUrl);
CLCG_REL(mContext);
CLCG_REL(mNormalColor);
- CLCG_REL(mEmphasizedColor);
+ CLCG_REL(mEmphasisColor);
[super dealloc];
}
@@ -111,22 +111,22 @@ -(id)initWithImageWidth:(CGFloat)w
mImgH = h;
mPadding = padding;
[self setSelectionStyle:UITableViewCellSelectionStyleBlue];
- [[self textLabel] setNumberOfLines:0];//set to 0 and calc height dynamically
[[self textLabel] setTextColor:[UIColor blackColor]];
- [[self textLabel] setBackgroundColor:[UIColor clearColor]];
+ [[self textLabel] setLineBreakMode:UILineBreakModeWordWrap];
+ [[self textLabel] setNumberOfLines:0];//set to 0 and calc height dynamically
[[self detailTextLabel] setTextColor:[UIColor grayColor]];
+ [[self detailTextLabel] setLineBreakMode:UILineBreakModeWordWrap];
[[self detailTextLabel] setNumberOfLines:0];
- [[self detailTextLabel] setAdjustsFontSizeToFitWidth:YES];
[[self detailTextLabel] setMinimumFontSize:9];
- [[self detailTextLabel] setBackgroundColor:[UIColor clearColor]];
+ [[self detailTextLabel] setBaselineAdjustment:UIBaselineAdjustmentAlignCenters];
[[self imageView] setFrame:CGRectMake(padding, padding, w, h)];
[[self imageView] setAutoresizingMask:UIViewAutoresizingNone];
[[self imageView] setContentMode:UIViewContentModeScaleAspectFit];
[[self textLabel] setFont:[UIFont boldSystemFontOfSize:15.0f]]; //reasonable default
[[self detailTextLabel] setFont:[UIFont systemFontOfSize:12.0f]];//reasonable default
[mInfoTextLabel setFont:[UIFont systemFontOfSize:12.0f]]; //reasonable default
- mEmphasizedColor = [UIColor colorWithRed:1.0 green:0.98 blue:0.85 alpha:1.0];
- [mEmphasizedColor retain];
+ mEmphasisColor = [UIColor colorWithRed:1.0 green:0.98 blue:0.85 alpha:1.0];
+ [mEmphasisColor retain];
[self setNormalColor:[UIColor whiteColor]];
// info label, this goes below the detail label
@@ -136,6 +136,11 @@ -(id)initWithImageWidth:(CGFloat)w
[mInfoTextLabel setBackgroundColor:[UIColor clearColor]];
[self addSubview:mInfoTextLabel];
+ // NOTE: despite what the docs say, it seems necessary to set the background
+ // color here to have the emphasis color render correctly behind the labels.
+ [[self textLabel] setBackgroundColor:[UIColor clearColor]];
+ [[self detailTextLabel] setBackgroundColor:[UIColor clearColor]];
+
// needed for changing the background color
UIView *bgview = [[UIView alloc] initWithFrame:CGRectZero];
[bgview setOpaque:YES];
@@ -153,7 +158,7 @@ -(void)updateBackgroundColor
// Note: setting the background color on the contentView or even all the
// subviews doesn't take care of changing the background of the accessoryView.
// Setting the background of the accessoryView doesn't seem to work either.
- UIColor *color = (mEmphasized ? mEmphasizedColor : mNormalColor);
+ UIColor *color = (mEmphasized ? mEmphasisColor : mNormalColor);
[[self backgroundView] setBackgroundColor:color];
}
@@ -257,12 +262,21 @@ +(void)setMaxAccessoryWidth:(CGFloat)w
}
+/*!
+ This method calculates the available width for the text content.
+ It accounts for:
+ - image width
+ - accessory item (we assume it's either present/absent on all views)
+ - padding left and right of the cell's borders,
+ - padding on the right side of the image, if we have it,
+ - padding on the left side of the accessory view, if we have it.
+ */
+(CGFloat)textLabelWidthWithCellW:(CGFloat)maxw
imageW:(CGFloat)imgw
padding:(CGFloat)pad
{
- return maxw - imgw - ((imgw>0) ? pad:0) - pad
- - CLCG_DEFAULT_VIEWPORT_PADDING*2 - [self maxAccessoryWidth];
+ CGFloat accw = [self maxAccessoryWidth];
+ return maxw - imgw - pad*2 - (imgw>0 ? pad:0) - accw - (accw>0 ? pad:0);
}

0 comments on commit 6526d0c

Please sign in to comment.