我有代表产品名称的NSString字符串数量价格
我需要像这样对齐这些值的列

Productname         Qty    Price
PLAIN T-SHIRT         5    50.00
BLACK DENIM           1    29.99
BLUE DENIM            3    29.99
STRIPED DRESS         1    49.99
BLACK BOOTS           2    35.99


我怎么尝试使用

+(NSString *) get_TOT:(NSString *)tot_STR : (int) length_range
{
   NSString *tmp_TT;
   NSUInteger length = tot_STR.length;
   NSRange range;
    tmp_TT = [NSString stringWithFormat:@"                                 %d    %f",Qty,pricc];
    if (length <= 33)
    {
        range = NSMakeRange(33-length, length);
        tmp_TT = [tmp_TT stringByReplacingCharactersInRange:range withString:tot_STR];
    }
    else
    {
        tmp_TT = [tmp_TT substringToIndex:33];
    }
return tmp_TT;
}


我不确定这里出了什么问题
提前致谢

最佳答案

哇!添加硬编码的空格以获得所需的UI将是一种非常糟糕的方法。
您应该使用NSAttributedStrings获得中心对齐。

08-27 19:41
查看更多