开发者

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 th开发者_如何转开发e editor but it's still showing up in the UILabel and it makes the text layout look very messy.

How can I resolve this?


Try with below

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


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

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

This will remove the tabs completely.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜