-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
want to change TabBar line width #1109
Comments
Hey! I don't know why you want to change tabbar line width, but that does not work because the line width changed via animation: Material/Sources/iOS/TabBar.swift Lines 602 to 603 in 6b989a4
When you tap a tabItem or swipe the controller, above code is called. |
Actually there is hackish way to achieve what you want. Since the frame of the line is calculated from class MyTabsController: TabsController, TabBarDelegate {
override func prepare() {
super.prepare()
tabBar.delegate = self
}
func tabBar(tabBar: TabBar, willSelect tabItem: TabItem) {
let desiredWidth: CGFloat = 100
let w = tabItem.frame.width
let x = tabItem.center.x
tabItem.frame.size.width = desiredWidth
tabItem.frame.origin.x = x - desiredWidth / 2
DispatchQueue.main.asyncAfter(deadline: .now() + 0.01) {
tabItem.frame.size.width = w
tabItem.frame.origin.x = x - w / 2
}
}
@DanielDahan What do yo think maybe we should add something like: func tabBar(tabBar: TabBar, lineWidthFor tabItem: TabItem) -> CGFloat |
I think for the purposes of customization, we can offer an enum that is by default set to |
Well, that sounds reasonable. Can tabItems have different widths? If so, then lines can also have different widths based on tabItem's width. So, we need another case accepting closure for dynamic calculation. enum TabBarLineWidthStyle {
case auto
case fixed(CGFloat)
case custom((TabBarItem) -> CGFloat)
} Usage: tabBar.tabBarLineWidthStyle = .auto
tabBar.tabBarLineWidthStyle = .fixed(100)
tabBar.tabBarLineWidthStyle = .custom { tabItem in
return tabItem.bounds.width - 20
} What do you think? |
I think the 3 options would solve all cases nicely. Maybe we can rename the enum to |
Please find the solution for this in Material 2.16.2. Thank you! |
I want to change the width of TabBar line.
I tried the following in the subclass of TabsController but it didn't work.
How can I do this?
The text was updated successfully, but these errors were encountered: