Commit 05c17716 by Daniel Dahan

added auto TabBarStyle for scrolling

parent fa10e98d
...@@ -59,7 +59,8 @@ public protocol TabBarDelegate { ...@@ -59,7 +59,8 @@ public protocol TabBarDelegate {
@objc(TabBarStyle) @objc(TabBarStyle)
public enum TabBarStyle: Int { public enum TabBarStyle: Int {
case `default` case auto
case nonScrollable
case scrollable case scrollable
} }
...@@ -78,7 +79,7 @@ open class TabBar: Bar { ...@@ -78,7 +79,7 @@ open class TabBar: Bar {
} }
/// An enum that determines the tab bar style. /// An enum that determines the tab bar style.
open var tabBarStyle = TabBarStyle.default { open var tabBarStyle = TabBarStyle.auto {
didSet { didSet {
layoutSubviews() layoutSubviews()
} }
...@@ -277,18 +278,23 @@ open class TabBar: Bar { ...@@ -277,18 +278,23 @@ open class TabBar: Bar {
layoutDivider() layoutDivider()
if .scrollable == tabBarStyle {
scrollView.frame = CGRect(x: l, y: 0, width: p, height: height)
var w: CGFloat = 0 var w: CGFloat = 0
for b in buttons { for v in buttons {
let width = b.sizeThatFits(CGSize(width: CGFloat.greatestFiniteMagnitude, height: contentView.height)).width + interimSpace w += v.sizeThatFits(CGSize(width: CGFloat.greatestFiniteMagnitude, height: contentView.height)).width + interimSpace
scrollView.addSubview(b) }
b.height = scrollView.height
b.width = width if .scrollable == tabBarStyle || (w > bounds.width && .auto == tabBarStyle) {
b.x = w scrollView.frame = CGRect(x: l, y: 0, width: p, height: height)
w += width
w = 0
for v in buttons {
let x = v.sizeThatFits(CGSize(width: CGFloat.greatestFiniteMagnitude, height: contentView.height)).width + interimSpace
scrollView.addSubview(v)
v.height = scrollView.height
v.width = x
v.x = w
w += x
} }
scrollView.contentSize = CGSize(width: w, height: height) scrollView.contentSize = CGSize(width: w, height: height)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment