LoginSignup
18
21

More than 5 years have passed since last update.

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

Last updated at Posted at 2014-12-31

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

スクリーンショット 2014-12-31 21.00.30.png

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)
    }
}

18
21
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
18
21