8

我试图让标签将一位数显示为两位数(即 1 => 01)。我可能使用了错误的方法来设置标签的值,但问题是在翻阅了 Apple 的文档并搜索了互联网之后,我什至不确定这一点。

[secondsLabel setValue:[NSString stringWithFormat:@"%2d", seconds]]

我看到其他人将 stringWithFormat 用作 stringWithFormat:@"%.2f" 所以我想我会尝试类似的东西并将其更改为 "%2d",但不走运。感谢您提前提供帮助。

4

1 回答 1

34

你非常接近:尝试"%.2d"(注意“。”)。

方法中格式字符串的参考-stringWithFormat:IEEE printf规范

于 2010-04-21T10:24:33.363 回答