In the Human Interface Guidelines for tvOS under "Tab Bar Customization" it states that:
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.
In the UITabBar
docs the the following property is available:
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
And there is a trailing version too.
-
HOWEVER... trailingAccessoryView
is defined as read only:
var leadingAccessoryView: UIView { get }
So it can not be set directly in code.
I've found no way to set it in a Storyboard file, either directly on a UITabBarController UITabBar, on a UITabBar placed directly on a view controller, or by draging UIViews across onto the UITabBar.
I've also tried setting it by creating a custom UITabBar and overriding that property, like so: class CustomTabBar:
UITabBar {
override var leadingAccessoryView: UIView {
return UIImageView(image: UIImage(named: "example-image"))
}
}
I've verified that I have set the tab bar in storyboard to my custom one, and it is using the custom one, but the leadingAccessoryView
value is never accessed, and the view it returns is never displayed.
-
How does one set a leadingAccessoryView
on a UITabBar
in tvOS?
-
Environment:
Xcode version 11.0 (11A420a)
Project deployment target: tvOS 13.0
Simulator: Apple TV 4K - tvOS 13.0 (17J577)
This question has also been posted on the Apple Developer Forums: https://forums.developer.apple.com/thread/123469
You have to add your view as a subview.
Example:
let imageView = UIImageView(image: UIImage(named: "example-image"))
tabBar.leadingAccessoryView.addSubview(imageView)