Ram*_*sel -1 objective-c nsstring stringwithformat
我正在更改一些预先编写的代码,视频时间标签的格式如下:
return [NSString stringWithFormat:@"%2d:%0.2d", minutes, seconds];
Run Code Online (Sandbox Code Playgroud)
发生的情况是,如果minutes是单个数字,它会在它之前返回一个空格,例如4:494 之前有一个空格。如果参数是 2 位数字minutes,但只有 1 个字符,如何格式化以使字符串中有 2 个字符如果minutes是1位数字?
您想要以下内容:
return [NSString stringWithFormat:@"%d:%02d", minutes, seconds];
Run Code Online (Sandbox Code Playgroud)
只需使用%d即可显示所需的任意位数的数字。而且不seconds应该有小数。据说%02d至少要显示两位数字,并在左侧填充前导零,以确保在需要时有两位数字。
| 归档时间: |
|
| 查看次数: |
3364 次 |
| 最近记录: |