1234567891011121314151617181920212223242526272829303132333435363738394041 |
- //
- // CustomTabBar.m
- // DouBanProject
- //
- // Created by wuli萍萍 on 16/5/6.
- // Copyright © 2016年 wuli萍萍. All rights reserved.
- //
- #import "CustomTabBar.h"
- #define NUM_TAB 3.0
- @implementation CustomTabBar
- - (void)layoutSubviews
- {
-
- [super layoutSubviews];
- // [self setBackgroundImage:[UIImage imageNamed:@"background_tab"]];
- // [self setBackgroundColor:[UIColor clearColor]];
- //
- // [self setShadowImage:[UIImage new]];
-
- //系统自带的按钮类型是UITabBarButton,找出这些类型的按钮,然后重新排布位置,空出中间的位置
- Class class = NSClassFromString(@"UITabBarButton");
-
-
- int btnIndex = 0;
- for (UIView *btn in self.subviews) {//遍历tabbar的子控件
- if ([btn isKindOfClass:class]) {
- btn.width = self.width / NUM_TAB;
-
- btn.x = btn.width * btnIndex;
-
- btnIndex++;
-
- }
- }
-
- }
- @end
|