Search code examples
iosobjective-cnsstring

How do I add spaces after a string


I am wanting to add spaces after a string in objective c....so I can perform some padding.

I have viewed the method at this question - How can I add leading whitespace in front of the NSString?

But it only seems to work for spaces in front of a NSString.

Edit: These don't seem to be working, here is some information.

I am performing this inside - (void)tableView: (UITableView*)tableView willDisplayCell: (UITableViewCell*)cell forRowAtIndexPath: (NSIndexPath*)indexPath - Where I have an image being displayed also to the right of the text. But my text is too close to the image. I know I can create a UITextView to deal with this, but this then leads to other issues. Hence the spaces at the end of the text being the simplest solution....but this does not seem to work inside a cell.


Solution

  • Another simple technique

    NSString *yourString = @"Objective-c is easy";    
    NSString *spaceString = @"       ";
    NSString *finalString = [NSString stringWithFormat:@"%@%@",yourString,spaceString];