无法在 tvOS 13 上设置 UITabBar leadingAccessoryView
Cannot set UITabBar leadingAccessoryView on tvOS 13
在 Human Interface Guidelines for tvOS under "Tab Bar Customization" 中指出:
In addition, you can display a logo or other information when the tab
bar is visible by supplying accessory views that appear near the
leading and trailing ends of the tab bar.
在 UITabBar
文档中,以下 属性 可用:
trailingAccessoryView
The view at the trailing edge of a tab bar on tvOS. Use this property
to integrate a custom view at the leading edge of your tab bar
interface. Use this view to display a custom logo or give access to
custom accessories in your app.
https://developer.apple.com/documentation/uikit/uitabbar/3213944-leadingaccessoryview
还有一个trailing version。
-
然而...trailingAccessoryView
被定义为只读:
var leadingAccessoryView: UIView { get }
所以不能直接在代码中设置
我发现无法在 Storyboard 文件中设置它,要么直接在 UITabBarController UITabBar 上,要么在直接放置在视图控制器上的 UITabBar 上,要么通过将 UIViews 拖到 UITabBar 上。
我还尝试通过创建自定义 UITabBar 并覆盖 属性 来设置它,如下所示:
class自定义标签栏:
UITabBar {
override var leadingAccessoryView: UIView {
return UIImageView(image: UIImage(named: "example-image"))
}
}
我已经确认我已经将情节提要中的标签栏设置为我的自定义标签栏,并且它使用的是自定义标签栏,但是从未访问 leadingAccessoryView
值,并且查看它 returns 永远不会显示。
-
如何在 tvOS 中的 UITabBar
上设置 leadingAccessoryView
?
-
环境:
Xcode 版本 11.0 (11A420a)
项目部署目标:tvOS 13.0
模拟器:Apple TV 4K - tvOS 13.0 (17J577)
Apple 开发者论坛也发布了这个问题:
https://forums.developer.apple.com/thread/123469
您必须将视图添加为子视图。
示例:
let imageView = UIImageView(image: UIImage(named: "example-image"))
tabBar.leadingAccessoryView.addSubview(imageView)
在 Human Interface Guidelines for tvOS under "Tab Bar Customization" 中指出:
In addition, you can display a logo or other information when the tab bar is visible by supplying accessory views that appear near the leading and trailing ends of the tab bar.
在 UITabBar
文档中,以下 属性 可用:
trailingAccessoryView
The view at the trailing edge of a tab bar on tvOS. Use this property to integrate a custom view at the leading edge of your tab bar interface. Use this view to display a custom logo or give access to custom accessories in your app.
https://developer.apple.com/documentation/uikit/uitabbar/3213944-leadingaccessoryview
还有一个trailing version。
-
然而...trailingAccessoryView
被定义为只读:
var leadingAccessoryView: UIView { get }
所以不能直接在代码中设置
我发现无法在 Storyboard 文件中设置它,要么直接在 UITabBarController UITabBar 上,要么在直接放置在视图控制器上的 UITabBar 上,要么通过将 UIViews 拖到 UITabBar 上。
我还尝试通过创建自定义 UITabBar 并覆盖 属性 来设置它,如下所示: class自定义标签栏:
UITabBar {
override var leadingAccessoryView: UIView {
return UIImageView(image: UIImage(named: "example-image"))
}
}
我已经确认我已经将情节提要中的标签栏设置为我的自定义标签栏,并且它使用的是自定义标签栏,但是从未访问 leadingAccessoryView
值,并且查看它 returns 永远不会显示。
-
如何在 tvOS 中的 UITabBar
上设置 leadingAccessoryView
?
-
环境:
Xcode 版本 11.0 (11A420a)
项目部署目标:tvOS 13.0
模拟器:Apple TV 4K - tvOS 13.0 (17J577)
Apple 开发者论坛也发布了这个问题: https://forums.developer.apple.com/thread/123469
您必须将视图添加为子视图。
示例:
let imageView = UIImageView(image: UIImage(named: "example-image"))
tabBar.leadingAccessoryView.addSubview(imageView)