SimpleTabというUITabBarControllerがオシャレになったようなライブラリを試してみました。
CocoaPodsでインストールします。
target 'MyApp' do use_frameworks! pod 'SimpleTab' end
2017/10/3時点ではSwift4に対応していないので、Swift3で動かします。
まずはStoryboardだけで動かしてみます。
最初にタブバー用の適当な画像を追加します。
続けてStoryboard上にUITabBarControllerを設置してタブバーの画像やタイトルを設定します。
そしてUITabBarControllerのクラスをSimpleTabBarControllerにします。
続けて、UITabBarControllerのUITabBarのクラスをSimpleTabBarに変更します。
最後にUITabBarControllerに設置するUITabItemのクラスをSimpleTabBarItemに変更します。
以上で設定完了です。
アプリを起動すると、アニメーション付きのタブバーが表示されている事が分かります。
冒頭の弾むようなアニメーションは、SimpleTabBarControllerのtabBarStyleをPopTabBarStyleにする事で実現できます。
import UIKit import SimpleTab @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { if let c = window?.rootViewController as? SimpleTabBarController { c.tabBarStyle = PopTabBarStyle(tabBar: c.tabBar) } return true } }
タブバーのアイコンの色やテキストのフォントサイズは、tabBarStyleで変更できます。
if let c = window?.rootViewController as? SimpleTabBarController { c.tabBarStyle = PopTabBarStyle(tabBar: c.tabBar) c.tabBarStyle?.setIconColor(color: UIColor.green, forState: .selected) }