由于字符的宽度不同,字符的数量会有所不同。 a W比* l **更长,所以一堆W将比一堆l更快地被截断。
通过试验和错误,你可以使用的NSString的方法- (CGSize)sizeWithFont:(UIFont *)字体找出允许在徽章的最大宽度。你将不得不弄清徽章使用的字体大小。你的代码应该会看起来像这样...
// I'm not sure what the badge font size is, you will have to test for this
UIFont *font = [UIFont systemFontOfSize:12];
// Keep adding 1's to the badge string until you get the ...'s, then you will
// know the maximum size of the badge string!
NSString *badgeString = @"111";
NSLog(@"width: %f", [badgeString sizeWithFont:font].width);
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:badgeString];