0

我用它来填写 UILabel:

storeName.text = [self.receivedLocation.name stringByReplacingOccurrencesOfString:@"Store" withString:@""];

但这会导致在标签的开始左侧插入一个明显的空间。我该如何解决?

4

1 回答 1

0

如果你的字符串有一个值,Store some more stuff那么结果将是some more stuff前导空格仍然存在。

尝试这个:

// Get original text
NSString *label = self.receivedLocation.name;
// Remove occurrences of "Store"
label = [label stringByReplacingOccurrencesOfString:@"Store" withString:@""];
// Trim any leading and/or trailing whitespace
label = [label stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
storeName.text = label;
于 2013-07-20T23:38:54.240 回答