有人知道苹果手表状态栏的大小吗?
我在苹果手表人机界面指南和苹果手表编程指南中都没有找到这个值。
有人知道苹果手表状态栏的大小吗?
我在苹果手表人机界面指南和苹果手表编程指南中都没有找到这个值。
所以,我已经测量过它们了。
38毫米 - 19pt
(38像素)
42毫米 - 21pt
(42像素)
这个技巧是设置白色背景并测量从顶部边缘到白色内容开始的距离。希望对某些人有用。
适用于Watch系列7或更高版本的状态栏高度:
为什么与1-3系列相比有很大的差异?因为状态栏必须考虑到圆角半径。
用法
let currentDevice = WKInterfaceDevice.current()
let statusBarHeight : CGFloat = currentDevice.statusBarHeight()
扩展
import WatchKit
extension WKInterfaceDevice {
func statusBarHeight() -> CGFloat {
// current device
let currentDevice = WKInterfaceDevice.current()
let bounds = currentDevice.screenBounds
let retinaFactor = currentDevice.screenScale
// dimensions in pixels
let width = bounds.width * retinaFactor
let height = bounds.height * retinaFactor
// 38mm: statusBar = 19pt (38px), screenBounds: 272 x 340
if width == 272.0 && height == 340.0 {
return 19.0
}
// 40mm: statusBar = 28pt (56px), screenBounds: 324 x 394
if width == 324.0 && height == 394.0 {
return 31.0
}
// 41mm: statusBar = 34pt (68px), screenBounds: 352 x 430
if width == 352.0 && height == 430.0 {
return 34.0
}
// 42mm: statusBar = 21pt (42px), screenBounds: 312 x 390
if width == 312.0 && height == 390.0 {
return 21.0
}
// 44mm: statusBar = 31pt (62px), screenBounds: 368 x 448
if width == 368.0 && height == 448.0 {
return 31.0
}
// 45mm: statusBar = 35pt (70px), screenBounds: 396 x 484
if width == 396.0 && height == 484.0 {
return 35.0
}
// 49mm: statusBar = 37pt (74px), screenBounds: 410 x 502
if width == 410.0 && height == 502.0 {
return 37.0
}
// default to 38mm
return 19.0
}
}
https://developer.apple.com/design/resources/#watchos-apps
根据上面的链接,更新了片段:
import WatchKit
extension WKInterfaceDevice {
func statusBarHeight() -> CGFloat {
// current device
let currentDevice = WKInterfaceDevice.current()
let bounds = currentDevice.screenBounds
let retinaFactor = currentDevice.screenScale
// dimensions in pixels
let width = bounds.width * retinaFactor
let height = bounds.height * retinaFactor
if #available(watchOS 10, *) {
switch (width, height) {
// 40mm: statusBar = 28pt (56px), screenBounds: 324 x 394
case (324, 394):
return 32 //
// 41mm: statusBar = 34pt (68px), screenBounds: 352 x 430
case (352, 430):
return 38 //
// 44mm: statusBar = 31pt (62px), screenBounds: 368 x 448
case (368, 448):
return 38 //
// 45mm: statusBar = 35pt (70px), screenBounds: 396 x 484
case (396, 484):
return 42 //
// 49mm: statusBar = 37pt (74px), screenBounds: 410 x 502
case (410, 502):
return 46 //
// default to 40mm
default:
return 32
}
} else {
switch (width, height) {
// 38mm: statusBar = 19pt (38px), screenBounds: 272 x 340
case (272, 340):
return 19
// 40mm: statusBar = 28pt (56px), screenBounds: 324 x 394
case (324, 394):
return 31
// 41mm: statusBar = 34pt (68px), screenBounds: 352 x 430
case (352, 430):
return 34
// 42mm: statusBar = 21pt (42px), screenBounds: 312 x 390
case (312, 390):
return 21
// 44mm: statusBar = 31pt (62px), screenBounds: 368 x 448
case (368, 448):
return 31
// 45mm: statusBar = 35pt (70px), screenBounds: 396 x 484
case (396, 484):
return 35
// 49mm: statusBar = 37pt (74px), screenBounds: 410 x 502
case (410, 502):
return 37
// default to 38mm
default:
return 19
}
}
}
}
为了补充缺失的尺寸,这是Apple Watch Ultra
49毫米 - 37pt(74像素)