gpt4 book ai didi

ios - Material 组件选项卡 Swift 中的项目大小

转载 作者:行者123 更新时间:2023-12-01 19:39:18 25 4
gpt4 key购买 nike

enter image description here

我想自动调整项目的大小以适应 UITabBarItem 的数量。但是,项目的大小不会自动调整。
我想要两个充满标签栏的项目,其中三个充满标签栏。

目前,标签栏有一个项目,但标签栏未满,因为大小是恒定的。

enter image description here

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)
}

我必须添加哪些选项才能使项目像“ Material 组件”选项卡中的示例一样填充选项卡栏?

最佳答案

如何在 configureTabBar() 中添加以下代码

tabBar.alignment = .justified

编辑:
MDCTabBar 具有称为“对齐”的属性,因此根据 MaterialComponents MDCTabBar.h 和 MDCTabBar.m 中的文档:

Property 'alignment' is Horizontal alignment of tabs within the tab bar. Changes are not animated. Default alignment is MDCTabBarAlignmentLeading. The default value is based on the position and is recommended for most applications



对齐是 MDCTabBarAlignment 枚举类型,有四种枚举:

  1. MDCTabBarAlignmentLeading -> Items are aligned on the leading edge and sized to fit their content

  2. MDCTabBarAlignmentJustified -> Items are justified to equal size across the width of the screen. Overscrolling is disabled for this alignment.

  3. MDCTabBarAlignmentCenter -> Items are sized to fit their content and center-aligned as a group. If they do not fit in view, they will be leading-aligned instead.

  4. MDCTabBarAlignmentCenterSelected -> Tabs are center-aligned on the selected item.

关于ios - Material 组件选项卡 Swift 中的项目大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56964794/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com