4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Safariのタブのように動くライブラリを作ってみた!!

Last updated at Posted at 2020-10-26

実装イメージ

コード

Podfile
pod 'TDTabView'
ViewController
class ViewController: TDTabViewController {
    
    var vc1: UIViewController!
    var vc2: UIViewController!
    var vc3: UIViewController!

    override func viewDidLoad() {
        super.viewDidLoad()
        self.delegate = self
        
        let storyboard1 = UIStoryboard(name: "Table", bundle: nil)
        vc1 = storyboard1.instantiateInitialViewController()
        
        let storyboard2 = UIStoryboard(name: "Image", bundle: nil)
        vc2 = storyboard2.instantiateInitialViewController()
        
        let storyboard3 = UIStoryboard(name: "Web", bundle: nil)
        vc3 = storyboard3.instantiateInitialViewController()
    }
}

extension ViewController: TDTabViewControllerDelegate {
    func viewControllers() -> [UIViewController] {
        return [vc1, vc2, vc3]
    }
    
    func backgroundColor() -> UIColor? {
        return UIColor(red: 50/255, green: 50/255, blue: 50/255, alpha: 0.8)
    }
}

ポイント

class ViewController: TDTabViewController {

TDTabViewControllerを継承したViewControllerを作成します。


extension ViewController: TDTabViewControllerDelegate {
    func viewControllers() -> [UIViewController] {
        return [vc1, vc2, vc3]
    }
    
    func backgroundColor() -> UIColor? {
        return UIColor(red: 50/255, green: 50/255, blue: 50/255, alpha: 0.8)
    }
}

TDTabViewControllerDelegateを追加して、タブとして表示させたいViewControllerを返すだけ!とってもかんたん!

自作ライブラリを作ってみての感想

主な機能は1日でできたのですが、UIに納得がいかず(まだ改善したいところはありますが)、UI改善に2週間ぐらいかかってしまいました。。。

よかったら使ってあげてください!そしてLGTMをください(*´-`)

gitはこちら
https://github.com/ymarui/TDTabView

おわり

4
2
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
4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?