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 { var w: CGFloat = 0
for v in buttons {
w += v.sizeThatFits(CGSize(width: CGFloat.greatestFiniteMagnitude, height: contentView.height)).width + interimSpace
}
if .scrollable == tabBarStyle || (w > bounds.width && .auto == tabBarStyle) {
scrollView.frame = CGRect(x: l, y: 0, width: p, height: height) scrollView.frame = CGRect(x: l, y: 0, width: p, height: height)
var w: CGFloat = 0 w = 0
for v in buttons {
for b in buttons { let x = v.sizeThatFits(CGSize(width: CGFloat.greatestFiniteMagnitude, height: contentView.height)).width + interimSpace
let width = b.sizeThatFits(CGSize(width: CGFloat.greatestFiniteMagnitude, height: contentView.height)).width + interimSpace scrollView.addSubview(v)
scrollView.addSubview(b) v.height = scrollView.height
b.height = scrollView.height v.width = x
b.width = width v.x = w
b.x = w w += x
w += width
} }
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