ios - SwiftUI tvOS 按钮看起来很奇怪
问题描述
我正在尝试为 iOS 和 tvOS 设置相同的 SwiftUI 按钮样式,以便两个平台都可以重用它……对于 iOS,样式按预期进行,没有任何问题,但是在 tvOS 上运行相同按钮时,它们看起来与iOS版本:
IOS:
电视操作系统:
为什么 tvOS 版本的按钮上有前导和尾随?
...
var body: some View {
Button(action: tapEvent) {
HStack {
if let image = icon, let uiimage = UIImage(named: image) {
Image(uiImage: uiimage)
.resizable()
.renderingMode(.template)
.foregroundColor(iconColorForState(active: active, buttonMode: mode))
.frame(width: 20, height: 20, alignment: .center)
}
if let title = label {
Text(title)
.lineLimit(1)
}
}
}
.foregroundColor(foregroundColorForState(active: active, buttonMode: mode))
.padding()
.disabled(disabled)
.background(self.focused ? focussedBackgroundColorFor(active: active, mode: mode) : backgroundColorFor(active: active, mode: mode))
.frame(height: heightForButtonSize(size: size ?? .Base))
.cornerRadius(8)
.modifier(FocusableModifier { focused in
self.focused = focused
})
}
解决方案
推荐阅读
- html - `overflow-wrap: break-word` 和 `word-break: break-word` 的行为是否有所不同?
- javascript - 如何使元素始终位于结束标签上
- google-chrome - Windows Docker 容器中的 Chrome 安装失败:非零代码 3221225781
- javascript - 我将字符串发布到后端,但后端返回状态码 500:查看函数未返回响应
- c++ - 从变量转换时出现 std::chrono::time_point 编译器错误
- python - 如何找到组中两个事件之间的时间差
- php - 如何使用 php 从文本文件中获取特定文本?
- wordpress - 使用 Post View Counter 按查看次数最多对 Woocommerce 产品进行排序
- html - 使用 2 Pages 以角度过滤表格
- schema.org - 如何使用“职业”类型使用链接的数字副本标记法律许可?