Devgeeks

  • Archive
  • RSS

Raised center TabBar button in Cordova / PhoneGap for iOS

A popular pattern in iOS lately (especially in apps with a focus on photo taking) is the raised / highlighted middle TabBar button. It’s easy enough to get a native TabBar in an iOS PhoneGap app using one of the two popular plugins (NativeControls and TabBar). There is even a great article on getting a raised middle TabBar button on iOS.

But not everyone using PhoneGap can comfortably turn that article into a modified TabBar plugin. There was even a recent thread on this topic in the PhoneGap Google Group recently.

Since I have done this in one of my apps, I thought I might post a quick outline on how to use the code in the iDevRecipes article above to get one of these buttons into one of the plugins above.

The Button Image

aperture-tab.png

This is the button I created for my app Pixfor. It’s basically just a green tinted screenshot of the middle third of a standard TabBar with an Aperture icon and a subtle shadow. You certainly don’t need to have a tinted gradient as well as your larger icon or whatever. That’s just a design decision. The great thing about how this works is that the touch goes straight through the added UIButton, so the highlight of the TabBar still happens so if your button image has transparency, it will show through nicely.

The button image is named aperture-tab.png and also has a corresponding aperture-tab@2x.png image for retina devices.

Note: these images (unlike the icons normally used in the TabBar plugins as icons) are added to the project through XCode as a resource, not just copied into the www folder with the other PhoneGap assets.

The JavaScript Code

For the JavaScript code, all you really need to do is create a TabBar item with an empty label and an empty icon.

For example, in NativeControls:

window.plugins.nativeControls.createTabBarItem("takepix", "", "", options);

and in TabBar:

window.plugins.tabBar.createItem("takepix", "", "", options);

The Objective-C Code

Pixfor happens to use the NativeControls plugin, but the code below should work in both.

They both have a method in their respective .m files that creates the TabBar (create in TabBar and createTabBar in NativeControls). *

Both these methods end with

[self.webView.superview addSubview:tabBar];

What we are going to do is add the following code directly after this line before the closing brace.

This code will add a custom UIButton using our image centered on our TabBar. Note the file name aperture-tab.png in the first line. The retina @2x version does not need to be explicitly referenced.

Pixfor's raised middle button

And there it is! Our special TabBar button.









* Line numbers only used for illustration. Please find the methods above in the plugin’s latest version.

    • #phonegap
    • #cordova
    • #ios
    • #plugins
    • #Pixfor
  • 5 months ago
  • 1
  • Permalink
Share

Short URL

TwitterFacebookPinterestGoogle+

1 Notes/ Hide

  1. wearetriumphant likes this
  2. therealdevgeeks posted this
← Previous • Next →

About

Avatar Software development in the minutes a day I have spare

Pages

  • iPhone/iPad apps
  • Android apps
  • PhoneGap / Cordova plugins

Me, Elsewhere

  • @theRealDevgeeks on Twitter
  • devgeeks on github

I Dig These Posts

See more →
  • Post via photokandy
    Getting Started with Cordova-CLI

    Cordova-CLI is doing some great things to make working with multiple platforms in one Cordova project easier. But...

    Post via photokandy
  • Post via taitems
    An Autopsy of a Bad User Experience

    I’d like to take a moment to share a bad user experience with you. Why? I believe it’s important to diagnose the...

    Post via taitems
  • Post via taitems
    More Form Failures

    In the post directly below I discussed the ramifications of bad form design on the overall customer experience. I compared...

    Post via taitems
  • RSS
  • Random
  • Archive
  • Mobile
Effector Theme by Pixel Union