Yalantis / FoldingTabBar.iOS

Folding Tab Bar and Tab Bar Controller
https://yalantis.com
MIT License
3.68k stars 458 forks source link

Xib or code example #56

Closed tunidev closed 8 years ago

tunidev commented 8 years ago

I wonder:

1) if it's possible to use this pod without storyboard, and just use code or xib

if 1) is true, is there any example else thx :)

serejahh commented 8 years ago

Hi @tunidev. Thanks for your interest to our component! Yes, it is possible. Unfortunately, we don't have the example, but you can easily do what you want:

  1. Create an empty xib
  2. Add UITabBarViewController
  3. Set YALFoldingTabBarController class or your custom one for the view controller
  4. Set YALCustomHeightTabBar class for tabbar
  5. Create an instance using [NSBundle -loadNibNamed:owner:options:]

Let me know if you need some help 😉

dmattia commented 8 years ago

A quick example of this: In AppDelegate.swift

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    self.window = UIWindow(frame: UIScreen.mainScreen().bounds)

    let nav1 = UINavigationController()
    let first = UIViewController()
    nav1.viewControllers = [first]

    let nav2 = UINavigationController()
    let second = UIViewController()
    nav2.viewControllers = [second]

    let tabBarController: YALFoldingTabBarController = self.prepareTabBarController()
    tabBarController.viewControllers = [nav1, nav2]

    self.window?.rootViewController = tabBarController;

    self.window?.makeKeyAndVisible();

    return true
}

func prepareTabBarController() -> YALFoldingTabBarController{
    let tabBarController = YALFoldingTabBarController()

    // This uses the ionicons pod
    let profileImage = IonIcons.imageWithIcon(ion_person, size: 28, color: MaterialColor.white)
    let homeImage = IonIcons.imageWithIcon(ion_home, size: 28, color: MaterialColor.white)
    let settingsImage = IonIcons.imageWithIcon(ion_gear_b, size: 28, color: MaterialColor.white)
    let menuImage = IonIcons.imageWithIcon(ion_android_add, size: 28, color: MaterialColor.white)

    tabBarController.tabBarView.tabBarViewEdgeInsets = YALTabBarViewHDefaultEdgeInsets
    tabBarController.tabBarView.tabBarItemsEdgeInsets = YALTabBarViewItemsDefaultEdgeInsets
    tabBarController.tabBarView.offsetForExtraTabBarItems = YALForExtraTabBarItemsDefaultOffset
    tabBarController.tabBarView.extraTabBarItemHeight = YALExtraTabBarItemsDefaultHeight

    tabBarController.tabBarView.tabBarColor = MaterialColor.blue.base
    tabBarController.tabBarView.backgroundColor = MaterialColor.blue.lighten2
    tabBarController.tabBarView.dotColor = MaterialColor.blue.lighten5
    tabBarController.centerButtonImage = menuImage

    let firstItem = YALTabBarItem(
        itemImage: profileImage,
        leftItemImage: homeImage,
        rightItemImage: settingsImage
    )

    let secondItem = YALTabBarItem(
        itemImage: settingsImage,
        leftItemImage: homeImage,
        rightItemImage: settingsImage
    )

    tabBarController.leftBarItems = [firstItem]
    tabBarController.rightBarItems = [secondItem]

    return tabBarController
}

And to change the tab bar height: Outside of any class

extension UITabBar {
    override public func sizeThatFits(size: CGSize) -> CGSize {
        var sizeThatFits = super.sizeThatFits(size)
        sizeThatFits.height = 69

        return sizeThatFits
    }
}
tunidev commented 8 years ago

@dmattia thank you so much that's really helpful