Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In case you are struggling with a custom UITabBarItem taller than the UITabBar height, a solution that let you preserve your default UITabBar shadowImage and backgroundImage (with the blur effect) is achieved by using CALayer.</p> <p>I am using this code in my UITabBarController subclass:</p> <pre><code>- (id) init { if ((self = [super init])) { self.delegate = self; CALayer * superLayer = self.tabBar.layer; CALayer * layer = [CALayer layer]; layer.bounds = CGRectMake (0.0f, 0.0f, 62.0f, 56.0f); layer.contents = (id) [UIImage imageNamed: @"custom-tabbaritem"].CGImage; layer.anchorPoint = CGPointMake (0.5f, 1.0f); layer.position = CGPointMake (superLayer.bounds.size.width / 2.0f, superLayer.bounds.size.height); layer.zPosition = 1.0f; [self.tabBar.layer addSublayer: layer]; } return self; } </code></pre> <p>Note that you can also use <code>layer.frame = CGRectMake (...)</code> in place of <code>bounds</code>, <code>anchorPoint</code> and <code>position</code>. I am using these ones to better deal with images with various heights by anchoring the sublayer to the bottom of the <code>UITabBar</code>. By implementing a UITabBarControllerDelegate method such as <code>tabBarController:shouldSelectViewController:</code> it is possible to make this <code>UITabBarItem</code> do custom actions, for example presenting a modal view controller.</p> <p>In this case I used a plain <code>UIViewController</code> as the view controller for the custom <code>UITabBarItem</code> (the other ones are all subclasses):</p> <pre><code>- (BOOL) tabBarController: (UITabBarController *) tabBarController shouldSelectViewController: (UIViewController *) viewController { if ([viewController isMemberOfClass: [UIViewController class]]) { SomeViewController * modal = [SomeViewController new]; [tabBarController presentViewController: modal animated: YES completion: nil]; modal = nil; return NO; } return YES; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload