Ivan Karpan
Ivan Karpan

Reputation: 1554

iOS - How to reclaim the top 20px in storyboard w/ translucent black status bar

I have a problem with top 20px behind status bar, specifically I cannot put anything there.

When I created the UI I used the storyboard approach and set status bar style to translucent black. But when do the layout in Xcode my views' height is fixed to 460px (grayed out).

Please help.


Got an answer from a friend, will mark his solution as right answer as soon as he posts it here. For now here is the solution:

  1. In Interface Builder set up the view controller as wanting full screen and of freeform size: http://cl.ly/0x1p1u3q3B1y3b3C3U2n
  2. Then in the view's size settings set its height to 480px: http://cl.ly/1p1b0e060p1Y37393D08
  3. Ensure status bar style is translucent black in the Info.plist: http://cl.ly/153Y391S1b0G3J3z3Y1O
  4. Get satisfactory result: http://cl.ly/0Q1M390i3A3h2F3u2T19

Upvotes: 3

Views: 9524

Answers (4)

Cowirrie
Cowirrie

Reputation: 7226

Okay, having been told it's possible, I tried placing a view on top of the main view and setting its y coordinate to -20. Then I west to Info.plist and set Status bar style to Transparent black style (alpha of 0.5). The view I placed was visible beneath the status bar.

enter image description here

This only happened at run time; in Interface Buider the simulated translucent status bar is gray but opaque.

Edit: If you want to move your view controller's main view into this space, it is possible during viewWillAppear. (If you try to move it during viewDidLoad, it gets moved back afterwards.)

- (void)viewWillAppear:(BOOL)animated;
{
    [super viewWillAppear:animated];

    // Move the main view upwards if it isn't already there.
    CGRect frame = [[self view] frame];
    frame.size.height += frame.origin.y;
    frame.origin.y = 0;
    [[self view] setFrame:frame];
}

However, it gets moved back after rotation, and my attempts to respond to rotation ended up breaking the cell layout if I did this to a UITableView.

Here is the Swift version. Seems to work. Good solution for taking those App Store screen shots (well in addition to making the info.plist changes.

override func viewWillAppear(animated: Bool) {

    super.viewWillAppear(animated)

    // Move the main view upwards if it isn't already there.
    var frame: CGRect = self.view.frame
    frame.size.height += frame.origin.y
    frame.origin.y = 0
    self.view.frame = frame
}

Upvotes: 2

Eugene Belyakov
Eugene Belyakov

Reputation: 86

Here's solution without single line of code.

  1. In Interface Builder set up the view controller as wanting full screen and of freeform size.
  2. In the view's size settings set its height to 480px
  3. Ensure status bar style is translucent black in the Info.plist.
  4. Launch and observe

See the links for screenshots of each step in the top post.

Upvotes: 7

samson
samson

Reputation: 1152

Try changing the value for "Status Bar" in the "Simulated Metrics" section of the Attributes inspector in Interface Builder. If you set it to "Inferred", Xcode will make no assumptions about the view controller, allowing you to set the size of the view to ANY size you want (even sizes that don't make any sense). Check out this post about the status bar for info on hiding it in your app.

Upvotes: -1

invoodoo
invoodoo

Reputation: 3906

Just make negative Y (-20) coordinate in interface builder.

Upvotes: 1

Related Questions