Search code examples
iosxcodeswifttabbar

Adding a center button to a UITabBar SWIFT


I would like to add a main button to a UITabBar as shown in the image: main button, the button i wish to add meaning i would like to add a button in the center of the bar, the button will be a bit higher then the other buttons( the regular buttons of an UITabBar)


Solution

  • If you're using Interface Builder:

    1. Drag a UIButton to the view
    2. Set the size constraints (ex: width 80, height 80)
    3. Align Center X to Superview
    4. Align Bottom to Tab Bar: -20

    In your View Controller:

    1. Add an IBOutlet for the button
    2. Then in viewDidLoad under super.ViewDidLoad() add:

      button.layer.zposition = 1

    It should give you this result:

    enter image description here

    You can lower the image by increasing the negative number on the bottom constraint.