简体   繁体   中英

How can I remove tab spacing from text for UILabel

I'm reading some text from a local xml file and displaying it in a UILabel. The text in the xml initially had tabbed spacing in it. I removed this tabbing manually in the editor but it's still showing up in the UILabel and it makes the text layout look very messy.

How can I resolve this?

When you assign the text to your label you can do this:

myLabel.text = [textWithTabs stringByReplacingOccurrencesOfString:@"\t" withString:@""];

This will remove the tabs completely.

尝试以下

myLabel.text = [myText stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet];

stringByTrimmingCharactersInSet: Returns a new string made by removing from both ends of the receiver characters contained in a given character set.

- (NSString *)stringByTrimmingCharactersInSet:(NSCharacterSet *)set

NSString Class Reference

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM