NSString stringWithFormat - 尝试将单位数字的标签设置为两位数
我试图让标签将单位数字显示为两位数字(即 1 => 01)。我可能使用了错误的方法来设置标签的值,但事实是,在翻阅了苹果的文档并搜索了互联网之后,我什至不确定这一点。
[secondsLabel setValue:[NSString stringWithFormat:@"%2d", seconds]]
我看到其他人使用 stringWithFormat 作为 stringWithFormat:@"%.2f" 所以我想我会尝试类似的东西并将其更改为 "%2d",但没有运气。感谢您提前提供帮助。
I am trying to have a label display single-digit numbers as double-digit numbers (ie. 1 => 01) . I may be using the wrong method to set the value for the label but the thing is I'm not even sure about that after pouring over Apple's documentation and scouring the internet.
[secondsLabel setValue:[NSString stringWithFormat:@"%2d", seconds]]
I saw someone else's use of stringWithFormat as stringWithFormat:@"%.2f" so I figured I would try something similar and change it to "%2d", no luck. Thanks for you help in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您非常接近:尝试
"%.2d"
(注意“.”)。-stringWithFormat:
方法中格式字符串的参考是 IEEE printf 规范You were very close: try
"%.2d"
(note the ".").The reference for the format string in the
-stringWithFormat:
method is the IEEE printf specification