-2

My scenario, I am trying to create centre circle button in UITabbarViewController. I tried many sample but not getting output like below Image. Please provide some code to achieve this. I am using storyboard for this.

sample Image

app dev
  • 19
  • 7
  • I think it is already answered [here](https://stackoverflow.com/questions/30527738/how-do-we-create-a-bigger-center-uitabbar-item) – Abhishek Maurya Jul 24 '19 at 07:03
  • 1
    Possible duplicate of [How do we create a bigger center UITabBar Item](https://stackoverflow.com/questions/30527738/how-do-we-create-a-bigger-center-uitabbar-item) – Mandeep Singh Jul 24 '19 at 07:26

1 Answers1

1

You need to do is your UITabbarViewController must contain five tabs in bottom tab bar that you can do by adding five view controller and make sure the middle tab contain no title and icon.

After that in onCreate method of your UITabbarViewController add this custom button Code -

    let button = UIButton(type: .custom)
    var toMakeButtonUp = 40 
    button.frame = CGRect(x: 0.0, y: 0.0, width: 65, height: 65)
    button.setBackgroundImage(ADD, for: .normal)
    button.setBackgroundImage(ADD, for: .highlighted)
    let heightDifference: CGFloat = CGFloat(toMakeButtonUp)
    if heightDifference < 0 {
        button.center = tabBar.center
    } else {
        var center: CGPoint = tabBar.center
        center.y = center.y - heightDifference / 2.0
        button.center = center
    }
    button.addTarget(self, action: #selector(btnTouched), for:.touchUpInside)
    view.addSubview(button)

FYI - toMakeButton is the margin from bottom you can set it accordingly. and #selector(btnTouched) is the function defined in class which will perform on click on the button.

enter image description here

matt
  • 515,959
  • 87
  • 875
  • 1,141
Abhishek
  • 329
  • 3
  • 12