fuzzygoat
fuzzygoat

Reputation: 26223

Where to customise UITabBar?

A simple question, I am doing some UI customisation on a UITabBar loaded from a storyboard (changing tint colours, setting images for the tabBar background etc.). My question is where is the best place to do this, I am not using IBOutlets just objects that are layed out in the storyboard. Currently I am using initWithCoder:, but someone mentioned awakeFromNib: (which does not seem right to me) so I just wanted to check.

Upvotes: 0

Views: 178

Answers (2)

Danilo Campos
Danilo Campos

Reputation: 6479

-awakeFromNib is a perfectly acceptable place to call methods that style the view, if you're certain you'll always use a nib to load it. But the same goes for using -initWithCoder.

I most often use -awakeFromNib for a few reasons. First, from the docs:

The nib-loading infrastructure sends an awakeFromNib message to each object recreated from a nib archive, but only after all the objects in the archive have been loaded and initialized. When an object receives an awakeFromNib message, it is guaranteed to have all its outlet and action connections already established.

For the moment, this isn't important to you, as you're not touching any outlets. But after awhile, you may end up using them, and it's nice to see all your customization/setup work covered in a single method.

-viewDidLoad is another option. Good for setup/customization when you want to support a view being loaded programmatically or from a nib.

Upvotes: 1

Alex Stuckey
Alex Stuckey

Reputation: 1260

I would either:

  • Create the UI objects entirely in programmatically
  • Or create UI objects in the storyboard, then connect IBOutlets to those Objects

Then in the initWithCoder: method you can customize the UITabBar.

Upvotes: 1

Related Questions