【发布时间】:2019-07-10 06:45:15
【问题描述】:
我想自动调整项目的大小以适应 UITabBarItem 的数量。但是,项目的大小不会自动调整。 我想要两个充满标签栏的项目,其中三个充满标签栏。
目前,标签栏有一个项目,但标签栏未满,因为大小是恒定的。
let tabBar = MDCTabBar(frame: CGRect(x: 0, y: 88, width: 414, height: 40))
override func viewDidLoad() {
super.viewDidLoad()
configureTabBar()
}
func configureTabBar() {
tabBar.items = [
UITabBarItem(title: "one", image: .none, tag: 0),
UITabBarItem(title: "two", image: .none, tag: 0),
]
tabBar.itemAppearance = .titledImages
tabBar.autoresizingMask = [.flexibleWidth, .flexibleBottomMargin]
tabBar.sizeToFit()
tabBar.tintColor = UIColor.red
tabBar.barTintColor = UIColor.white
tabBar.rippleColor = UIColor.red
tabBar.bottomDividerColor = UIColor.lightGray
tabBar.unselectedItemTintColor = UIColor.gray
tabBar.selectedItemTintColor = UIColor.red
view.addSubview(tabBar)
}
我必须添加哪些选项才能使项目像“材料组件”选项卡中的示例一样填充选项卡栏?
【问题讨论】:
-
嗨@caleb,你能分享一张你想要的照片吗?
-
嗨@Emre Ciffci!我加了两张照片!上图是我想要的,下图是我实现的视图。
-
您可以简单地为此创建自定义 segmentedControl。为什么要使用 tabBar?
-
我要创建的应用是图书应用。我们需要一个标签栏来显示这本书的类型。帮助
-
我认为你应该使用自定义
segmentedControl,查看 Bruno Faganello 的 Medium 文章 -> medium.com/code-with-coffee/… 我希望它有效。