Iphone 字符串之间的灵活空格?

Iphone 字符串之间的灵活空格?,iphone,objective-c,ios,ios4,Iphone,Objective C,Ios,Ios4,在我的应用程序中,我想创建一个用于打印的收据布局。我正在努力创建字符串之间的正确对齐 我想创建这样的东西(正确对齐) 目前我已经这样做了 NSMutableString* strBody = [NSMutableString string]; for (int i=0; i<[arrItems count];i++){ [strBody appendString:[NSString stringWithFormat:@"\n%@ %@ %@",[[arrIte

在我的应用程序中,我想创建一个用于打印的收据布局。我正在努力创建字符串之间的正确对齐

我想创建这样的东西(正确对齐)

目前我已经这样做了

NSMutableString* strBody = [NSMutableString string];
for (int i=0; i<[arrItems count];i++){
    [strBody appendString:[NSString stringWithFormat:@"\n%@           %@  %@",[[arrItems objectAtIndex:i] objectForKey:@"ProductName"],[[arrItems objectAtIndex:i] objectForKey:@"ProductQuantity"],[[arrItems objectAtIndex:i] objectForKey:@"Comment"]]];
}
NSMutableString*strBody=[NSMutableString];

对于(int i=0;i您可以创建单独的
UILabel
并使用
setFrame
属性对齐所有标签


或者使用
\t
(制表符取决于字符串的长度…

可能会重复欢迎…但有时\t会在字符串太短或太长时产生问题…请记住。。。
NSMutableString* strBody = [NSMutableString string];
for (int i=0; i<[arrItems count];i++){
    [strBody appendString:[NSString stringWithFormat:@"\n%@           %@  %@",[[arrItems objectAtIndex:i] objectForKey:@"ProductName"],[[arrItems objectAtIndex:i] objectForKey:@"ProductQuantity"],[[arrItems objectAtIndex:i] objectForKey:@"Comment"]]];
}