20
self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, [UIScreen mainScreen].bounds.size.height ) style:UITableViewStylePlain];

enter image description here

If I change the tableview frame to

(0.0, 0.0, 320.0, [UIScreen mainScreen].bounds.size.height -49.0)

enter image description here

the scroll bar will leave a blank,I do not like it.How can I fix this?

Thank you very much.

Suhaib
  • 2,031
  • 3
  • 24
  • 36
jxdwinter
  • 2,339
  • 6
  • 36
  • 56
  • possible duplicate of [Tab bar covers UITableView's last cell](http://stackoverflow.com/questions/3463157/tab-bar-covers-uitableviews-last-cell) – S1LENT WARRIOR May 04 '15 at 10:28

5 Answers5

50

You could try setting the contentInset of that table view. In iOS 7 there's a topLayoutGuide and bottomLayoutGuide (which is what you want). Inside of a UITabBarController the bottomLayoutGuide should give you the height of the bottom bar basically.

tableView.contentInset = UIEdgeInsetsMake(0, 0, self.bottomLayoutGuide.length, 0);

should do the trick.

rihekopo
  • 3,241
  • 4
  • 34
  • 63
Dennis
  • 2,223
  • 3
  • 27
  • 36
  • 4
    Thanks,tableView.contentInset = UIEdgeInsetsMake(0, 0, 49, 0) works! – jxdwinter Nov 01 '13 at 03:55
  • 6
    You probably want to avoid using any magic numbers here still. Especially when you support device rotation for instance. bottomLayoutGuide will always reflect the current height of your UITabBar. – Dennis Nov 01 '13 at 04:25
  • Yes sir, you are right.Now I'm using "self.bottomLayoutGuide.length". – jxdwinter Nov 01 '13 at 04:47
  • 3
    My self.bottomLayoutGuide.length when I log it returns 0. How can I fix it? Thanks! – jaytrixz Dec 28 '13 at 09:24
  • 8
    @jaytrixz It's probably 0 because layout has not occurred yet. Try updating the contentInset in your controller's viewDidLayoutSubviews method. – Bart Vandendriessche May 02 '14 at 08:08
29

Set the translucent property to NO

// In init or viewDidLoad of tab bar controller
self.tabBar.translucent = NO;

Now the tab bar should resize the table view.

The translucent property is available iOS 7 and up.

Eric Amorde
  • 1,068
  • 9
  • 19
4

You have 2 options:

First

self.tableView.contentInset.bottom = self.tabBarController?.tabBar.frame.height ?? 0

This will do the trick and save the transparent property of the tab bar.


Second In design view just uncheck the option Under Bottom Bars, But put in your mind the tab bar will look like solid color (no thing behind it).

enter image description here

enter image description here

Wajih
  • 4,227
  • 2
  • 25
  • 40
  • I wanted to use heightForFooterInSection and return tabbar height , but "Under bottom bars" is better solution if u have tabbar with many tableviews. – ShadeToD Sep 21 '19 at 07:48
1

// In viewDidLoad() the following lines worked for me

self.edgesForExtendedLayout = UIRectEdge.None self.navigationController?.navigationBar.translucent = false self.tabBarController?.tabBar.translucent = false

Abhijeet Mallick
  • 1,740
  • 2
  • 16
  • 21
1

Swift:

self.tabBar.isTranslucent = false

Note: @Eric Amorde answers converted to Swift.

Hemang
  • 26,840
  • 19
  • 119
  • 186