Permalink
Browse files

Fixed error in width calculation for the space reserved to the text l…

…abels, and added/fixed comments
  • Loading branch information...
1 parent 2bd3240 commit 9e972ec3b90a50294720f78def7da18a06d0467b @ettore committed Dec 1, 2012
Showing with 23 additions and 18 deletions.
  1. +11 −2 CLCGCell.h
  2. +12 −16 CLCGCell.m
View
@@ -65,7 +65,15 @@
@property(nonatomic,retain) id context;//should this be assign?
@property(nonatomic,readonly) CGFloat padding;
-/*! 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
@@ -107,11 +115,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
@@ -47,19 +47,6 @@ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
*/
#define CLCG_DEFAULT_ACCESSORY_TYPE_W 22.0f
-
-/*!
- @discussion This accounts for left and right viewport padding added by iOS,
- since we are still using UITableViewCell for the layout of the image.
- @note This is fragile in the sense that it could change in future releases
- of iOS, but likely is not going to change by much more.
- @todo Nevertheless, we should remove this dependency and just derive this
- dynamically, although that can probably be done only at layout time
- (typically we want to use this before layout, to calculate the height of
- the cell.
- */
-#define CLCG_DEFAULT_VIEWPORT_PADDING 11.0f
-
/*! Construction time defaults. */
#define CLCGCELL_IMG_DEFAULT_W 60.0f
#define CLCGCELL_IMG_DEFAULT_H 60.0f
@@ -206,7 +193,7 @@ -(void)layoutSubviews
CGSize sz;
[super layoutSubviews];
-
+
// layout image view
[[self imageView] setFrame:CGRectMake(mPadding, mPadding, mImgW, mImgH)];
@@ -246,12 +233,21 @@ +(CGFloat)maxAccessoryWidth
}
+/*!
+ 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 9e972ec

Please sign in to comment.