I created a custom tab bar controller. It works very similar to UITabBarController
but with a more advanced layout for the UITabBar
.
How do I adjust the bottom content insets for views that appear in my custom tab bar controller? For instance if I show a UITableView
in my custom tab bar controller I can manually adjust the content insets like this.
self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 49, 0);
self.tableView.scrollIndicatorInsets = UIEdgeInsetsMake(0, 0, 49, 0);
However the problem gets more complicated if I push another view onto this table view like a collection view. Is there a way to get these views to automatically adjust their content insets like they do in the default UITabBarController
implementation?
We've recently done something similar in our app, and ended up simply having a container view that holds any content we're going to display in the controller. The advantage of this approach is that you can add whatever constraints you'd like to the container view (such as bottom padding between the container and the tab bar).
Container view with bottom padding to tab bar.
Edit: Misunderstood the question
You can simply check that the content view is able to setContentInset:
- (void)setContentInset:(UIEdgeInset)insets {
if ([self.contentView respondsToSelector:@selector(setContentInset:)]) {
[self.contentView setValue:insets forKey:@"contentInset"];
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With