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

  • SEARCH
  • Home
  • 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 8435721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:59:23+00:00 2026-06-10T06:59:23+00:00

I hava a format problem in cell-subtitle. I have a string and a number

  • 0

I hava a format problem in cell-subtitle.
I have a string and a number I want to show in subtitle of a cell

String should be left aligned, number right aligned

I tried it in that way:

rangeAutor = [rangeAutor stringByPaddingToLength:40-[rangeAutor length] withString:@" " startingAtIndex:0];

NSString *subTitle = [NSString stringWithFormat:@"by %@ %1.2f km", rangeAutor, rangeDistance];
cell.detailTextLabel.text = subTitle;

result can you see here 🙁 format problem

Do you have an idea for me for a solution?

due to the fact I only have 7 reputation, i cant write in comments my answer 🙁
So i try to do it here:

    static NSString *const kIdentifier = @"SelectRange";
static NSInteger const kDistanceLabelTag = 1;

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kIdentifier];
UILabel *distanceLabel;
if (cell) {
    distanceLabel = (UILabel *)[cell.contentView viewWithTag:kDistanceLabelTag];
} else {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:kIdentifier];
    CGRect cellBounds = cell.bounds;
    static CGFloat const kLabelHeight = 20.0f;
    distanceLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, cellBounds.size.height - kLabelHeight, cellBounds.size.width, kLabelHeight)];
    distanceLabel.tag = kDistanceLabelTag;
    distanceLabel.font = cell.textLabel.font;
    distanceLabel.textColor = cell.textLabel.textColor;
    distanceLabel.textAlignment = UITextAlignmentRight;
    distanceLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin;
    [cell.contentView addSubview:distanceLabel];
}

UIImage *icon = [UIImage imageNamed:iconName];;
cell.imageView.image = icon;
cell.textLabel.text = rangeName;
cell.detailTextLabel.text = [@"by " stringByAppendingString:rangeAutor];
distanceLabel.text = [NSString stringWithFormat:@"%1.2f km", rangeDistance];
NSLog(@"RangeDistance: %1.2f", rangeDistance);

return cell;

to rob mayoff

I changed only small things
but now I cant see rangeDistance in the cell 🙁
output of log is ok

  • 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-10T06:59:25+00:00Added an answer on June 10, 2026 at 6:59 am

    The problem is you’re using a variable-width font. Each glyph in the font may have a different width. So you can’t just pad the autor out to 40 characters, because “llll” followed by 36 spaces is a different width (on screen) than “MMMM” followed by 36 spaces.

    Just give your cell another label to hold the distance. I assume the code in your post is from your tableView:cellForRowAtIndexPath: method. You’ll need to do something like this:

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
        static NSString *const kIdentifier = @"Cell";
        static NSInteger const kDistanceLabelTag = 1;
    
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kIdentifier];
        UILabel *distanceLabel;
        if (cell) {
            distanceLabel = (UILabel *)[cell.contentView viewWithTag:kDistanceLabelTag];
        } else {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:kIdentifier];
            CGRect cellBounds = cell.bounds;
            static CGFloat const kLabelHeight = 20.0f;
            distanceLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, cellBounds.size.height - kLabelHeight, cellBounds.size.width, kLabelHeight)];
            distanceLabel.tag = kDistanceLabelTag;
            distanceLabel.font = cell.textLabel.font;
            distanceLabel.textColor = cell.textLabel.textColor;
            distanceLabel.textAlignment = UITextAlignmentRight;
            distanceLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin;
            [cell.contentView addSubview:distanceLabel];
        }
    
        cell.imageView.image = rangeImage;
        cell.textLabel.text = rangeName;
        cell.detailTextLabel.text = [@"by " stringByAppendingString:rangeAutor];
        distanceLabel.text = [NSString stringWithFormat:@"%1.2f km", rangeDistance];
    
        return cell;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I hava a problem with an error in ADT Plugin. I want to make
I hava a time string,the format is HHMM, I need to get the decimal
I hava a Bitmap variable named bmp in Activity1 , and I want to
I hava an activity which might have to load data when it's starting up.
I hava a UITextView ,and after some characters' input, I want to use a
I hava a CSV file that I want to treat as source code. Essentially
I hava an ArrayList of String values (they need to be formatted as such)
i hava two text boxs in flex.have to add two txt boxs values in
I hava a JFrame with multiple JPanels of similar width aligned one below other.
I hava a basic Hibernate/JPA question. I want to find a best practice solution

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.