Add option to select a different vertical alignment for ButtonBar’s SelectedBar: top, middle or bottom (default).

This commit is contained in:
Luis Valdés 2017-03-02 21:25:52 +00:00
parent 4f2d9d9838
commit d42269e5ab
2 changed files with 20 additions and 1 deletions

View File

@ -49,6 +49,7 @@ public struct ButtonBarPagerTabStripSettings {
public var selectedBarBackgroundColor = UIColor.black
public var selectedBarHeight: CGFloat = 5
public var selectedBarVerticalAlignment: SelectedBarVerticalAlignment = .bottom
public var buttonBarItemBackgroundColor: UIColor?
public var buttonBarItemFont = UIFont.systemFont(ofSize: 18)
@ -147,6 +148,8 @@ open class ButtonBarPagerTabStripViewController: PagerTabStripViewController, Pa
buttonBarView.selectedBar.backgroundColor = settings.style.selectedBarBackgroundColor
buttonBarView.selectedBarHeight = settings.style.selectedBarHeight
buttonBarView.selectedBarVerticalAlignment = settings.style.selectedBarVerticalAlignment
// register button bar item cell
switch buttonBarItemSpec! {
case .nibFile(let nibName, let bundle, _):

View File

@ -37,6 +37,12 @@ public enum SelectedBarAlignment {
case progressive
}
public enum SelectedBarVerticalAlignment {
case top
case middle
case bottom
}
open class ButtonBarView: UICollectionView {
open lazy var selectedBar: UIView = { [unowned self] in
@ -50,6 +56,7 @@ open class ButtonBarView: UICollectionView {
updateSelectedBarYPosition()
}
}
var selectedBarVerticalAlignment: SelectedBarVerticalAlignment = .bottom
var selectedBarAlignment: SelectedBarAlignment = .center
var selectedIndex = 0
@ -167,7 +174,16 @@ open class ButtonBarView: UICollectionView {
private func updateSelectedBarYPosition() {
var selectedBarFrame = selectedBar.frame
selectedBarFrame.origin.y = frame.size.height - selectedBarHeight
switch selectedBarVerticalAlignment {
case .top:
selectedBarFrame.origin.y = 0
case .middle:
selectedBarFrame.origin.y = (frame.size.height - selectedBarHeight) / 2
case .bottom:
selectedBarFrame.origin.y = frame.size.height - selectedBarHeight
}
selectedBarFrame.size.height = selectedBarHeight
selectedBar.frame = selectedBarFrame
}