Reputation: 1554
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:
Upvotes: 3
Views: 9524
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.
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
Reputation: 86
Here's solution without single line of code.
See the links for screenshots of each step in the top post.
Upvotes: 7
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