🔲 StackBarButtonItem can use BarButtonItem like StackView
StackBarButtonItem can use BarButtonItem like stackView.
If you’re using Carthage, simply add
StackBarButtonItem to your Cartfile
:
github "funzin/StackBarButtonItem"
StackBarButtonItem is available through CocoaPods. To instal
it, simply add the following line to your Podfile:
pod 'StackBarButtonItem'
position | Default | StackBarButtonItem |
---|---|---|
right | navigationItem.setRightBarButtonItems |
navigationItem.right.setStackBarButtonItems |
left | navigationItem.setLeftBarButtonItems |
navigationItem.left.setStackBarButtonItems |
If iOS version is iOS11 or later, you must use autolayout.
import StackBarButtonItem
・
・
・
// use autolayout
let rightButton = UIButton(frame: CGRect(x: 0, y: 0, width: 44, height: 44))
NSLayoutConstraint.activate([
rightButton.widthAnchor.constraint(equalToConstant: 44),
rightButton.heightAnchor.constraint(equalToConstant: 44)
])
self.navigationItem.right.setStackBarButtonItems(views: [rightButton])
If iOS version is iOS9 or iOS10, you must configure frame.
import StackBarButtonItem
・
・
・
// configure frame
let rightButton = UIButton(frame: CGRect(x: 0, y: 0, width: 44, height: 44))
self.navigationItem.right.setStackBarButtonItems(views: [rightButton])
// e.g. set margin to 10
self.navigationItem.right.setStackBarButtonItems(views: [rightButton], margin: 10)
Margin | ScreenShot |
---|---|
margin == 0 |
|
margin == 10 |
// e.g. set spacing to 10
self.navigationItem.right.setStackBarButtonItems(views: [rightButton1, rightButton2], spacing: 10)
Spacing | ScreenShot |
---|---|
spacing == 0 |
|
spacing == 10 |
// e.g. set reversed to true
self.navigationItem.right.setStackBarButtonItems(views: [rightButton1, rightButton2], reversed: true)
Reverse | ScreenShot |
---|---|
reversed == false |
|
reversed == true |
If you are interested in StackBarButtonItem, please check demo after carthage update
funzin, [email protected]
StackBarButtonItem is available under the MIT license. See the LICENSE file for more info.