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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T23:04:59+00:00 2026-05-21T23:04:59+00:00

I am trying to resize the height of my row in UITableView based on

  • 0

I am trying to resize the height of my row in UITableView based on the text length. I have the following code:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *cellText =[[topics objectAtIndex:indexPath.row] name];
    UIFont *cellFont = [UIFont fontWithName:@"ArialMT" size:17.0];
    CGSize constraintSize = CGSizeMake(280.0f, MAXFLOAT);
    CGSize labelSize = [cellText sizeWithFont:cellFont constrainedToSize:constraintSize lineBreakMode:UILineBreakModeWordWrap];

    return labelSize.height + 20;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
        cell.textLabel.lineBreakMode = UILineBreakModeWordWrap;
        cell.textLabel.numberOfLines = 0;
        cell.textLabel.font = [UIFont fontWithName:@"ArialMT" size:17.0];
    }
}

However, it messes up with the UIImageView and the UIDetailText, image shown below:

enter image description here

How do I fix this?

I’ve tried:

[cell.imageView setContentMode:UIViewContentModeScaleToFill];
    [cell.imageView setFrame:CGRectMake(0, 0, 16,16)];
    [cell.imageView setBounds:CGRectMake(0, 0, 16,16)];
    [cell.imageView setAutoresizingMask:UIViewAutoresizingNone];
    [cell.imageView setAutoresizesSubviews:NO];

and none seems to work

  • 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-21T23:05:00+00:00Added an answer on May 21, 2026 at 11:05 pm

    Instead of subclassing as suggested by others, you could also add your own subviews to the cell’s content view.

    From Customizing Cells:

    If you want the cell to have different
    content components and to have these
    laid out in different locations, or if
    you want different behavioral
    characteristics for the cell, you have
    two alternatives. You can add subviews
    to the contentView property of the
    cell object or you can create a custom
    subclass of UITableViewCell.

    • You should add subviews to a cell’s content view when your content layout can be specified entirely with the appropriate autoresizing settings and when you don’t need to modify the default behavior of the cell.
    • You should create a custom subclass when your content requires custom layout code or when you need to change the default behavior of the cell, such as in response to editing mode.

    See this example:

    #define CUSTOM_IMAGE_TAG 99
    #define MAIN_LABEL 98
    
    // Customize the appearance of table view cells.
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
        static NSString *CellIdentifier = @"Cell";
        UIImageView *customImageView = nil;
        UILabel *mainLabel = nil;
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
            customImageView = [[[UIImageView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 40.0f, 40.0f)] autorelease];
            customImageView.tag = CUSTOM_IMAGE_TAG;
            [cell.contentView addSubview:customImageView];
    
            mainLabel = [[[UILabel alloc] initWithFrame:CGRectMake(60.0f, 10.0f, 100.0f, 21.0f)] autorelease];
            mainLabel.tag = MAIN_LABEL;
            mainLabel.numberOfLines = 0;
            [cell.contentView addSubview:mainLabel];
        } else {
            customImageView = (UIImageView *)[cell.contentView viewWithTag:CUSTOM_IMAGE_TAG];
            mainLabel = (UILabel *)[cell.contentView viewWithTag:MAIN_LABEL];
        }
    
        // Configure the cell.
        CGRect frame = mainLabel.frame;
        frame.size.height = ... // dynamic height
        mainLabel.frame = frame;
    
        return cell;
    }
    

    Obviously, you still need to implement tableView:heightForRowAtIndexPath:.

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

Sidebar

Related Questions

I'm trying to get a row in my table view to resize its height,
I am trying to resize the height of a UITableViewCell depending on what text
I am trying to resize an image based off of a max-width/max-height array. Here's
I'm having a problem trying to programmatically resize the height of a UITableView hosted
Im trying to resize the tableview's height with a animation, it works fine by
I have a 3200x1200 png image I am trying to resize it to 200x200
I'm trying to align small boxes in a row. These boxes have something like
I am trying to write a javascript function to resize an image based on
I have a bunch of PDFs that I'm just trying to open, resize the
I'm trying to resize the container and set for it width and height. It

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.