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 9014377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:29:32+00:00 2026-06-16T03:29:32+00:00

So my rootViewController contains a UICollectionView with a Custom UICollectionViewCell. I have a label

  • 0

So my rootViewController contains a UICollectionView with a Custom UICollectionViewCell. I have a label on the cell for a header which shouldn’t ever change and I have a multi-line Label making up the body of the rest of the cell. When I launch the app it calls the sizeToFit correctly and top aligns everything so it isn’t centered. I click on one of the cells and go to the next view, then if I click the back button to go back to the rootViewController it does run the viewWillAppear method and reloads the data but the sizeToFit does not work and everything on the multi-line label becomes center aligned. It is still multiple lines but if there is only a couple of lines it sits in the center of the label and it doesn’t look good. How can I keep this so it is consistant. I have a left menu that will reload the rootViewController which will position the label correctly again but once I hit the back button from the secondViewController it is no longer aligned. Is there a way to make it clear all of the cells and reload them. I have tried the [collectionView reloadData]; in the viewWillAppear and it doesn’t work, it is currently called at the end of the connectionDidFinish which the network connection is called from the viewWillAppear method. Any assistance is appreciated.

This is the custom UICollectionViewCell code

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

    }
    return self;
}

// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
    [contentLabel setNumberOfLines:0];
    [contentLabel sizeToFit];
}

RootViewController

-(UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:
(NSIndexPath *)indexPath
{
    NSString *cellIdentifier = @"LocationListCell";
    LocationList *cell = [cv dequeueReusableCellWithReuseIdentifier:cellIdentifier 
                                                           forIndexPath:indexPath];

    [cell.titleBar setText:[value objectAtIndex:indexPath.row]];
    NSArray *tempObject = [[NSArray alloc] initWithArray:[self getData:[key   
                                           objectAtIndex:indexPath.row]]];

    NSMutableString *tempString = [[NSMutableString alloc] init];
    for (int i = 0; i < [tempObject count]; i++)
    {
        [tempString appendString:[tempObject objectAtIndex:i]];
        [tempString appendString:@"\r"];
    }
    //[cell.contentLabel sizeToFit];
    //[cell.contentLabel setNumberOfLines:0];
    [cell.contentLabel setText:tempString];
    return cell;
}
  • 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-06-16T03:29:33+00:00Added an answer on June 16, 2026 at 3:29 am

    Use this dynamic UILable with this custom method…

    just add this bellow method in your .m file

    -(float) calculateHeightOfTextFromWidth:(NSString*) text: (UIFont*)withFont: (float)width :(UILineBreakMode)lineBreakMode
    {
    [text retain];
    [withFont retain];
    CGSize suggestedSize = [text sizeWithFont:withFont constrainedToSize:CGSizeMake(width, FLT_MAX) lineBreakMode:lineBreakMode];
    
    [text release];
    [withFont release];
    
    return suggestedSize.height;
    }
    

    and use it like bellow..

       UILabel *yourLable = [[UILabel alloc]init];
        [yourLable setFrame:CGRectMake(110, 31, 200, 50)];        
        [yourLable setText:tempString];
        yourLable.lineBreakMode = UILineBreakModeWordWrap;
        yourLable.numberOfLines = 0;
        yourLable.font = [UIFont fontWithName:@"Helvetica" size:12];
    
        yourLable.frame = CGRectMake(yourLable.frame.origin.x, yourLable.frame.origin.y, 
                                 200,[self calculateHeightOfTextFromWidth:yourLable.text :yourLable.font :200 :UILineBreakModeWordWrap]  ); 
    
    
        yourLable.textColor = [UIColor darkGrayColor];
    
         cell.contentLabel = yourLable;
    

    hope this help you…

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

Sidebar

Related Questions

I have a UIViewController named RootViewController which contains a UITableView and a UITabBar (2
I have a root view controller which contains an outlet for my login view
in my splitviewcontroller iPad app I show a custom popover (which loads the rootviewController).
I have splitview and it contains rootviewcontroller(uitableviewcontroller subclass) and detailview(viewcontroller subclass). Now I have
I have a view controller which contains a table view, and which is wrapped
I have two view controllers name RootViewController and SecondViewController. In the FirstViewController I have
i have more viewcontroller that start from rootviewcontroller. So for example i start with
I know that if i have rootViewController that start with tabBar i can create
I have this button on the leftside of my UISplitViewController (RootViewController) that has a
I have a UIViewController named LoginViewController , and it is a rootViewController in the

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.