CustomTabBar.m 973 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. //
  2. // CustomTabBar.m
  3. // DouBanProject
  4. //
  5. // Created by wuli萍萍 on 16/5/6.
  6. // Copyright © 2016年 wuli萍萍. All rights reserved.
  7. //
  8. #import "CustomTabBar.h"
  9. #define NUM_TAB 3.0
  10. @implementation CustomTabBar
  11. - (void)layoutSubviews
  12. {
  13. [super layoutSubviews];
  14. // [self setBackgroundImage:[UIImage imageNamed:@"background_tab"]];
  15. // [self setBackgroundColor:[UIColor clearColor]];
  16. //
  17. // [self setShadowImage:[UIImage new]];
  18. //系统自带的按钮类型是UITabBarButton,找出这些类型的按钮,然后重新排布位置,空出中间的位置
  19. Class class = NSClassFromString(@"UITabBarButton");
  20. int btnIndex = 0;
  21. for (UIView *btn in self.subviews) {//遍历tabbar的子控件
  22. if ([btn isKindOfClass:class]) {
  23. btn.width = self.width / NUM_TAB;
  24. btn.x = btn.width * btnIndex;
  25. btnIndex++;
  26. }
  27. }
  28. }
  29. @end