views:

657

answers:

2

How can I display a Tab (\t) on a textview ?

I have a small piece of code (Example Below) which is well formated with Tab's and new lines. But when I view this code on a text view it does not show the tab's, but it does show the new lines.

@interface Animal : NSObject {
    NSString *name;
    NSString *description;
    NSString *imageURL;
}

Thanks for the help.

A: 

It may be that the UITextView class simply does not show tab characters, which is entirely possible, due to the fact that the user cannot enter a tab with the built-in keyboard. If this is the case, there is always the option of simply doing a replace on tabs to four spaces. If you need to later find those tabs, you could replace it with a tab followed by four spaces, since it seems that the tab is not displayed, it would not make a visual difference.

The other possibility is that the width of the UITextView does not permit showing the tabs and so they are ignored.

Ed Marty
A: 

UITextView remove Tab characters from text, but you can replace it with blank space.

description = [description stringByReplacingOccurrencesOfString: @"\t" withString: @"    "];
Augard