Jacek Kwiecień
Jacek Kwiecień

Reputation: 12639

Autolayout ignores UITabBar (content under the bar) on iOS7

I've set UITabBar as Opaque in Storyboard, but i still seems to be transulcent. When I set my custom UITabBarController with setBarStyle there is only OpaqueBlack availible.

But that the least of the problem. No matter what I do, content of my view gets positioned under the tab bar, like it ignored by ayutolayout. On Storyboard everything looks fine. something messes up in the runtime?

Oh the most important thing. The problem occurs on iOS7 only!

Here are my ViewController settings in storyboard:

enter image description here

And here is problematic content (UITableView) which gets positioned under the UITabBar on ios7 app. Looks fine in storyboard though:

enter image description here

And finally UITableView constraints:

enter image description here

Upvotes: 11

Views: 7160

Answers (4)

Antoine
Antoine

Reputation: 23986

In Swift UIRectEdgeNone is not available. You can achieve the same with the following code:

edgesForExtendedLayout = []

Upvotes: 0

Jacek Kwiecień
Jacek Kwiecień

Reputation: 12639

Putting this on viewDidLoad, solves the problem:

if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")) {
    [self setEdgesForExtendedLayout:UIRectEdgeNone];
}

Upvotes: 21

Vaibhav Saran
Vaibhav Saran

Reputation: 12908

create these macros in your project's <projectname>-Prefix.pch file so they will work globally:

#define SYSTEM_VERSION_EQUAL_TO(v)                  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
#define SYSTEM_VERSION_GREATER_THAN(v)              ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN(v)                 ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v)     ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)

Then put this after [super viewDidLoad] in viewDidLoad method of every viewController that's having this issue:

if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")) 
{
        [self setEdgesForExtendedLayout:UIRectEdgeNone];
}

Upvotes: 4

zinc1oxide
zinc1oxide

Reputation: 490

xCode also provides the programatic capability:

[self setEdgesForExtendedLayout:UIRectEdgeNone];

within your storyboard for a given ViewController via the Extend Edges section:

enter image description here

Simply disable both the Under Top Bars and Under bottom Bars options. They are on by default.

Upvotes: 9

Related Questions