1.创建继承自UITabBar控件的类CustomTabBar,代码如下:
#import "CustomTabBar.h"
@interface CustomTabBar ()
@property (nonatomic, strong)UIButton *roundButton;
@end
@implementation CustomTabBar
-(instancetype)initWithFrame:(CGRect)frame{
if (self = [super initWithFrame:frame]) {
self.roundButton.backgroundColor = [UIColor redColor];
self.roundButton.layer.cornerRadius = 30;
[self.roundButton addTarget:self action:@selector(roundButtonClicked) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:self.roundButton];
};
return self;
}
- (UIButton *)roundButton{
if (!_roundButton) {
_roundButton = [[UIButton alloc]init];
}
return _roundButton;
}
//点击了圆形按钮
- (void)roundButtonClicked {
}
- (void)layoutSubviews {
[super layoutSubviews];
CGFloat centerx = self.bounds.size.width * 0.5;
CGFloat centery = self.bounds.size.height * 0.5;
//根据情况设置