iOSのタブバーに画像付きボタンでハックする


iOSのタブバーに画像付きボタンを出すことでタブバーハックをしましょう。ハックすることで、通常のタブバーよりもアイキャッチを取ることが可能です。

TabBarの配下に入る画面ですべてでBaseViewController経由で継承すれば良いです。

BaseViewController.swift
import UIKit

class BaseViewController: UIViewController {    
    func appendCenterButton() {
        let button: UIButton! = UIButton.buttonWithType(UIButtonType.Custom) as? UIButton
        let image: UIImage? = UIImage(named:"button")

        button.setImage(image, forState: UIControlState.Normal)
        button.frame = CGRectMake(0, 0, 60, 70)
        button.addTarget(self, action: "onClick:", forControlEvents:.TouchUpInside)
        button.layer.position = CGPoint(x: self.view.frame.width / 2, y: UIScreen.mainScreen().bounds.size.height - button.frame.height + 40)
        button.layer.borderWidth = 0

        self.tabBarController?.view.addSubview(button)
    }

    @IBAction func onClick(sender: AnyObject) {
        var storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle())
        var mainViewController: UIViewController

        mainViewController = storyboard.instantiateViewControllerWithIdentifier("data")  as UIViewController
        // タブバーを非表示にする
        mainViewController.hidesBottomBarWhenPushed = true;
        self.navigationController?.pushViewController(mainViewController as UIViewController, animated: true)
    }
}