LoginSignup
0
0

RAMAnimatedTabBarControllerライブラリを使用時に真ん中のタブから始める方法(.selectedIndex)

Last updated at Posted at 2024-01-01

できなかった経緯

StoryBoard上でUITabBarControllerのClassをRAMAnimatedTabBarControllerに設定していたことにより、コード上でselectedIndexプロパティにアクセスできなかった

結論

新たにCustomTabBarController.swift等を作り、その中で読み込みたい外部ライブラリを継承してあげる。

やり方

1.StoryBoard上でTabBarControllerを作成する。
スクリーンショット 2024-01-01 22.44.59.png
2.TabBarController用の.swiftファイルを作成する
スクリーンショット 2024-01-01 22.49.07.png
3.名前は任意でつける(今回はCustomTabBarController)
68747470733a2f2f71696974612d696d6167652d73746f72652e73332e61702d6e6f727468656173742d312e616d617a6f6e6177732e636f6d2f302f333636303933392f34663864623064632d643931342d343066632d623562362d3435363566616235643530302e706e67.png

4.作成したCustomTabBarControllerを下記の様に編集
ここに、今回使用したい外部ライブラリ(RAMAnimatedTabBarController)を記述する。
こうすることにより、通常通りselectedIndexプロパティにアクセスが可能。

// CustomTabBarController.swift
import RAMAnimatedTabBarController

class CustomTabBarController: RAMAnimatedTabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        selectedIndex = 1 // 左から2番目のタブから始める
    }
    
}

4.TabBarControllerを選択し、Xcode右側>ShowTheIdentityInspector>CustomClassより
Classに先程作成したClassを選択(CustomTabBarController)
スクリーンショット 2024-01-01 22.53.59.png

参考

ChatGPT

0
0
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
0
0