我用它来填写UILabel:
storeName.text = [self.receivedLocation.name stringByReplacingOccurrencesOfString:@"Store" withString:@""];
但这导致在标签的左侧插入一个明显的空间。我该如何解决这个问题?
答案 0 :(得分: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;