【问题标题】:How to create a centre align Nsstring如何创建中心对齐 Nsstring
【发布时间】:2017-02-15 07:55:29
【问题描述】:

我有代表产品名称数量价格的 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;
}

我不确定这里出了什么问题 在此先感谢

【问题讨论】:

  • @Anbu.Karthik 谢谢,但我的问题是不要在框架内打印宽度是静态的,高度是动态的
  • 你把那段文字放在哪里?因为在我看来你应该使用一个 UITableView 和自定义 UITableViewCell qui 三个 UILabel。

标签: ios objective-c cocoa-touch


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-21
    • 1970-01-01
    相关资源
    最近更新 更多