chrislhardin
chrislhardin

Reputation: 1745

UILabel in UITableViewCell clips content when moved in Interface Builder

I have a UILabel inside a UITableViewCell in the latest version of Xcode. I dynamically add text to it with some line breaks and it automatically adjusts which in turn adjusts my table cell height. So long as I leave the UILabel alone in Interface builder, it all works fine. IfI attempt to move it just 1 pixel to the left or right, the content gets clipped down to a single line of text and every other line that is in the line is not viewable. It's actually pretty ridiculous. I've tried every setting for the label, but if I move it any, it clips all but the first line. Does anyone have any idea of anything else to try? I know it sounds pretty ridiculous.

- (CGFloat)heightForRowInInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation     {
    CGFloat width = (interfaceOrientation == UIInterfaceOrientationPortrait ||         interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) ?    kDescriptionLabelWidthPortrait : kDescriptionLabelWidthLandscape;
    CGFloat height = [[self descriptionString] sizeWithFont:_descriptionLabelFont constrainedToSize:CGSizeMake(width, MAXFLOAT)].height + kDescriptionLabelPadding;
 return MIN(MAX(height, kMinCellHeight), kMaxCellHeight); 

}

#define kDescriptionLabelWidthPortrait 429.0f
#define kDescriptionLabelWidthLandscape 685.0f
#define kDescriptionLabelPadding 50.0f
#define kDescriptionLabelFontName @"Helvetica"
#define kDescriptionLabelFontSize 14.0f
#define kMinCellHeight 44.0f
#define kMaxCellHeight 2009.0f

Upvotes: 3

Views: 451

Answers (4)

junaidsidhu
junaidsidhu

Reputation: 3580

This is going to help you, this a the Code from the CustomCell.m

- (void) updateWithComment:(Comment *) comment
{
    self.aComment = comment;

    [self.userBtn setTitle:[NSString stringWithFormat:@"%@ %@",comment.user.firstName,comment.user.lastName] forState:UIControlStateNormal];

    CGSize size =  [aComment.text sizeWithFont:[UIFont fontWithName:@"Helvetica" size:14.0] constrainedToSize:CGSizeMake(210, 999)];

    [self.textLbl setFrame:CGRectMake(textLbl.frame.origin.x, textLbl.frame.origin.y, 225, size.height)];

    [self.textLbl setText:aComment.text];
}

enter image description here

Upvotes: 1

bibo bode
bibo bode

Reputation: 1150

Try restarting XCode and your Mac, creating another UILabel, and changing its frame.

Upvotes: 0

Brendon
Brendon

Reputation: 882

Try setting the label's number of lines to 0. 0 allows as many lines as the label wants.

Upvotes: 1

Vishal Singh
Vishal Singh

Reputation: 4480

i am not sure but try unchecking use autoLayout for your xib file in identity and type section.

Upvotes: 1

Related Questions