Skip to content

Instantly share code, notes, and snippets.

@kezzico
Last active September 2, 2020 00:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kezzico/e23a6e88757f1c5b65dcae39f7996cdd to your computer and use it in GitHub Desktop.
Save kezzico/e23a6e88757f1c5b65dcae39f7996cdd to your computer and use it in GitHub Desktop.
Add button to center of UITabBarController
//
// CenterButtonTabBarController.swift
// FashionCritic
//
// Created by Lee Irvine on 1/5/18.
// Copyright © 2018 kezzi.co. All rights reserved.
//
import UIKit
class CenterButtonTabBarController: UITabBarController {
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.view.bringSubview(toFront: self.tabBar)
self.addCenterButton()
}
private func addCenterButton() {
let button = UIButton(type: .custom)
let square = self.tabBar.frame.size.height
button.frame = CGRect(x: 0, y: 0, width: square, height: square)
button.center = self.tabBar.center
self.view.addSubview(button)
self.view.bringSubview(toFront: button)
button.addTarget(self, action: #selector(didTouchCenterButton(_:)), for: .touchUpInside)
}
@objc
private func didTouchCenterButton(_ sender: AnyObject) {
print("!!")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment