我在弄清楚如何从适用于 iOS 的 Google Material Design 禁用标签栏的水平滚动时遇到问题。我打算制作一个带有 3 个选项卡选项的固定选项卡栏。
也许有人可以帮助我。先感谢您。
示例代码:
import UIKit
import MaterialComponents
import ChameleonFramework
class ViewController: UIViewController, MDCTabBarDelegate {
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .white
navigationController?.navigationBar.isTranslucent = false
setupView()
}
let tabBarContainer: MDCTabBar = {
let tabBar = MDCTabBar()
tabBar.barTintColor = .white
tabBar.items = [
UITabBarItem(title: "All Activities", image: nil, tag: 0),
UITabBarItem(title: "Bookmark", image: nil, tag: 0),
UITabBarItem(title: "My Journal", image: nil, tag: 0)
]
tabBar.itemAppearance = .titledImages
tabBar.autoresizingMask = [.flexibleWidth, .flexibleBottomMargin]
tabBar.sizeToFit()
tabBar.tintColor = UIColor.rgb(red: 12, green: 82, blue: 143)
tabBar.selectedItemTintColor = UIColor.rgb(red: 12, green: 82, blue: 143)
tabBar.unselectedItemTintColor = .lightGray
return tabBar
}()
func setupView() {
view.addSubview(tabBarContainer)
view.addConstraintsWithFormat("H:|[v0]|", views: tabBarContainer)
view.addConstraintsWithFormat("V:|[v0(48)]", views: tabBarContainer)
}
}