Search code examples
iphoneiosios7uitoolbaruistatusbar

iOS7 UIStatusBar blur not correct


I am using a UIToolbar for the controls at the top of the screen (There is no navigation controller) The toolbar has the look I want, however the status bar is entirely clear. I cannot seem to mimic the blur that the UIToolbar has in it's transparency. Has anyone come across a solution to this that does not involve using a navigation controller?

Scroll content behind status bar

Scroll no content behind status bar


Solution

  • UIBarPosition demo

    In Order to achieve this you need to implement methods in the UIBarPositioningDelegate protocol:

    https://developer.apple.com/library/ios/documentation/uikit/reference/UIBarPositioningDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intf/UIBarPositioningDelegate

    Here is the code:

    @interface ViewController : UIViewController <UIToolbarDelegate>
    
    @property (nonatomic, weak) IBOutlet UIToolbar * toolbar;
    
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        //we become the delegate
        self.toolbar.delegate = self;
    }
    
    -(UIBarPosition)positionForBar:(id<UIBarPositioning>)bar{
        //this tells our bar to extend its background to the top.
        return UIBarPositionTopAttached;
    }
    
    @end