Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6131375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:58:01+00:00 2026-05-23T16:58:01+00:00

I have a label added to a cell which has a dynamic height based

  • 0

I have a label added to a cell which has a dynamic height based on the text to be added to it. I have set my font size to be 12 as seen below:

CGFloat height = [CustomCell getIndividualLabelHeight:text];
NSLog(@"height of commet:%@ is %f",commentText, height);

CustomOHAttributLabel *label = [[CustomOHAttributLabel alloc]initWithFrame:CGRectMake(CELL_TEXT_LEFT_MARGIN, 2*CELL_SPACING+totalCommentLabelHeight, CELL_CONTENT_WIDTH - (CELL_TEXT_LEFT_MARGIN*2), height)];
[label setLabelwithText:text fontSize:12 andSubString:userName withURL:url];

However, in my getIndividualLabelHeight method, if I set the font to 12.0 as well (in setting of CGSize size), the text in the label might be truncated. It is only when I set it to 14 will the text not be truncated.

+ (CGFloat)getIndividualLabelHeight:(NSString *)text
{
    CGSize constraint = CGSizeMake(CELL_CONTENT_WIDTH - (CELL_CONTENT_MARGIN * 2), 20000.0f);

    //The full text will only show when I set fontsize to 14 (instead of 12)
    CGSize size = [text sizeWithFont:[UIFont systemFontOfSize:14] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];

    return size.height;
}

Anyone has any idea why I cannot set the same font size in my get height method as the actual font size I am using for my text?

I have added my implementation code for the CustomOHAttributLabel for further reference

 @implementation CustomOHAttributLabel

 - (CustomOHAttributLabel*) initWithFrame:(CGRect)frame
 {
     self = [super initWithFrame:frame];
     if (self) 
     {

     }
     return self;
 }


 - (void) setLabelwithText:(NSString *)text fontSize:(CGFloat)fontSize andSubString:(NSString *)subString withURL:(NSString *)url
 {
     NSMutableAttributedString* attrStr = [NSMutableAttributedString attributedStringWithString:text];
     [attrStr setFont:[UIFont systemFontOfSize:fontSize]];
     [attrStr setTextColor:[UIColor grayColor]];

     [attrStr setFont:[UIFont boldSystemFontOfSize:fontSize] range:[text rangeOfString:subString]];
     [attrStr setTextColor:[UIColor darkGrayColor] range:[text rangeOfString:subString]];

self.attributedText = attrStr;

[self addCustomLink:[NSURL URLWithString:url] inRange:[text rangeOfString:subString]];

}

@end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T16:58:02+00:00Added an answer on May 23, 2026 at 4:58 pm

    try this code:-

    CGSize labelsize;
        UILabel *commentsTextLabel = [[UILabel alloc] init];;
        commentsTextLabel.tag =50;
        [commentsTextLabel setNumberOfLines:0];
        [commentsTextLabel setBackgroundColor:[UIColor clearColor]];
        NSString *text=@"cakghaahsdlajsldjasdsa;dkas;dkasdkasdasp'dlasp'dlas'dlas'dlas'dlas'dlas'dlasdlasdlasdlasdlas'das'dlasdas";
        [commentsTextLabel setFont:[UIFont fontWithName:@"Helvetica"size:14]];
        labelsize=[text sizeWithFont:commentsTextLabel.font constrainedToSize:CGSizeMake(268, 2000.0) lineBreakMode:UILineBreakModeWordWrap];
        commentsTextLabel.frame=CGRectMake(10, 24, 268, labelsize.height);
        [cell.contentView addSubview:commentsTextLabel];
        [commentsTextLabel release];
    

    from this code you label height will adjust dynamically.
    Make sure if you are adding this label in your table view cell so don’t forgot to make the cell height dynamic also.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table cell for which I set its contentView to a custom
I have added some text to a UITableViewCell by creating the label with the
I have added Label to my ViewController.xib. The problem is that when the text
I have this label control in my web page <asp:Label ID=Label1 runat=server Text=test></asp:Label> And
I have a label that is sometimes empty. How do I set up a
I have a label like <label for=Some Feild >Some Text </label> Now I want
I've a UITableView which when a cell has the same content that other, this
I have a details Form with multiple textviews (label: field) that are added with
I have a JPanel, on it are added an image and label, in that
I have added multiple labels in My Tableview cell. I am displaying facebook message

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.