Bar*_*lka 5 ios swift swiftui dynamic-island
我有一个秒表在动态岛紧凑模式下运行,使用相同的字体和颜色。第一个屏幕截图是空闲秒表,第二个屏幕截图是正在运行的秒表。
我相信正确的状态应该是第一个截图。
代码(compactTrailing块内):
if stopwatch.isRunning {
// Stopwatch running state
Text(timerInterval: stopwatch.timeInterval, countsDown: false)
.font(.system(size: 14, weight: .medium))
.foregroundColor(iconTintDarkMode)
} else {
// Stopwatch idle state
Text(timerString(time: stopwatch.elapsedTime))
.font(.system(size: 14, weight: .medium))
.foregroundColor(iconTintDarkMode)
}
Run Code Online (Sandbox Code Playgroud)
定时器字符串方法:
func timerString(time: Double) -> String {
var result = ""
let hours = Int(time) / 3600
let minutes = Int(time) / 60 % 60
let seconds = Int(time) % 60
if hours > 0 {
result.append(String(format: "%02d:", hours))
}
result.append(String(format: "%02d:%02d", minutes, seconds))
return result
}
Run Code Online (Sandbox Code Playgroud)
有谁知道为什么有区别?
小智 3
这是个好问题。遇到同样的问题。我尝试了一些事情并最终得到了这个:
Text(Date().addingTimeInterval(300), style: .timer)
.frame(maxWidth: .minimum(50, 50), alignment: .leading)
.background(.red)
Run Code Online (Sandbox Code Playgroud)
这对我有用。但最小 x / y 值取决于文本视图有多大。我将背景设置为红色,以便您更好地了解该解决方案占用了多少空间。但对我来说,它看起来像是计时器样式文本中的一个错误。
| 归档时间: |
|
| 查看次数: |
951 次 |
| 最近记录: |