自定義TabBar,繼承於UITabBar,重寫兩個方法,如下:
#import "CustomTabBar.h"
@implementation CustomTabBar
#pragma mark - Override Methods
- (void)setFrame:(CGRect)frame{
if (self.superview &&CGRectGetMaxY(self.superview.bounds) !=CGRectGetMaxY(frame)) {
frame.origin.y =CGRectGetHeight(self.superview.bounds) -CGRectGetHeight(frame);
}
[super setFrame:frame];
}
#pragma mark - Initial Methods
- (instancetype)initWithFrame:(CGRect)frame{
self = [super initWithFrame:frame];
if (self) {
self.translucent = false;
self.backgroundColor = [UIColor whiteColor];
}
return self;
}
@end
然後在添加TabBar的地方設置一下
[self setValue:[[CustomTabBar alloc]init]forKey:@"tabBar"];