Skip to content

Commit

Permalink
Comment Cell height tweak
Browse files Browse the repository at this point in the history
  • Loading branch information
vetri02 committed Aug 4, 2015
1 parent dd1ccdd commit c7bfbf9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
1 change: 1 addition & 0 deletions HackerNews/CommentTableViewCell.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *textLeadingSpacing;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *imageLeadingSpacing;


@property (strong, nonatomic) NSDictionary *comment;
@property (weak, nonatomic) id<CommentUrlDelegate> urlDelegate;

Expand Down
21 changes: 16 additions & 5 deletions HackerNews/CommentTableViewCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ - (void)setComment:(NSDictionary *)comment {
NSUInteger commentCount = [commentArray count];
NSString *commentCountText = [NSString stringWithFormat:@"%@", @(commentCount)];



NSTimeInterval timeSince = [[comment valueForKey:@"time"] doubleValue];
NSDate *date = [[NSDate alloc] initWithTimeIntervalSince1970: timeSince];
NSString *ago = [date timeAgo];
Expand Down Expand Up @@ -71,9 +73,11 @@ - (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRan
}

+ (CGFloat)heightForComment:(NSDictionary *)comment {
NSString* text = [comment valueForKey:@"text"];
NSAttributedString * attributedString = [[NSAttributedString alloc] initWithString:text attributes:
@{ NSFontAttributeName: [UIFont systemFontOfSize:14]}];
//NSString* text = [comment valueForKey:@"text"];
//NSAttributedString * attributedString = [[NSAttributedString alloc] initWithString:text attributes:
// @{ NSFontAttributeName: [UIFont systemFontOfSize:14]}];

NSAttributedString *attributedString= [Utils convertHTMLToAttributedString:[comment valueForKey:@"text"]];

//its not possible to get the cell label width since this method is called before cellForRow so best we can do
//is get the table width and subtract the default extra space on either side of the label.
Expand All @@ -86,8 +90,15 @@ + (CGFloat)heightForComment:(NSDictionary *)comment {

//Add back in the extra padding above and below label on table cell.
const CGFloat topSpaceToSuperView = 37;
const CGFloat bottomSpaceToSuperView = 50;
rect.size.height = rect.size.height + topSpaceToSuperView + bottomSpaceToSuperView;

// if([[comment valueForKey:@"kids"] count] != 0){
// const CGFloat bottomSpaceToSuperViewCons = 50;
// rect.size.height = rect.size.height + topSpaceToSuperView + bottomSpaceToSuperViewCons;
// } else {
const CGFloat bottomSpaceToSuperView = 50;
rect.size.height = rect.size.height + topSpaceToSuperView + bottomSpaceToSuperView;
// }


//if height is smaller than a normal row set it to the normal cell height, otherwise return the bigger dynamic height.

Expand Down

0 comments on commit c7bfbf9

Please sign in to comment.