iphone - NSString stringWithFormat 问题

标签 iphone objective-c cocoa cocoa-touch

我正在尝试使用 NSString 构建一个小表。我似乎无法正确格式化字符串。

这是我的

[NSString stringWithFormat:@"%8@: %.6f",e,v]

其中 e 是来自其他地方的 NSString,v 是 float 。

我想要的是这样的输出:

Grapes:       20.3
Pomegranates:  2.5
Oranges:      15.1

我得到的是

Grapes:20.3
Pomegranates:2.5
Oranges:15.1

我怎样才能修复我的格式来做这样的事情?

最佳答案

您可以尝试使用 - stringByPaddingToLength:withString:startingAtIndex:

关于iphone - NSString stringWithFormat 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2700909/

相关文章:

iphone - 在 Objective-C 中生成具有随机数长度的随机数

cocoa - 放置在 NSTableView 上的行为

macos - NSFileManager 'copyItemAtPath:' 创建隔离文件副本

iphone - UIScrollView 后面的 UIButton

objective-c - 使用 SLComposeViewController 发布到 Twitter 在 iOS 8 设备上不工作

iphone - 在同一 View Controller 中进行一次、两次和三次点击操作

ios - 删除解析类和类中的对象

macos - 主 NSWindow 阴影不会像子窗口那样改变

iphone - 如何在 iPhone 应用程序上获得黑色状态栏?

iphone - 如何从 NSMutableString 中删除最后一个字符