效果:
#define standOutHeight 15
// 畫背景的方法瓤摧,返回 Tabbar的背景
- (UIImageView *)drawTabbarBgImageView {
CGFloat radius = 25;// 圓半徑
CGFloat allFloat= (pow(radius, 2)-pow((radius-standOutHeight), 2));// standOutHeight 突出高度 15
CGFloat ww = sqrtf(allFloat);
UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, -standOutHeight,SCREEN_WIDTH , tabBarHeight + standOutHeight)];
CGSize size = imageView.frame.size;
CAShapeLayer *layer = [CAShapeLayer layer];
UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:CGPointMake(size.width/2 - ww, standOutHeight)];
CGFloat angleH = 0.5*((radius-standOutHeight)/radius);
CGFloat startAngle = (1+angleH)*((float)M_PI); // 開始弧度
CGFloat endAngle = (2-angleH)*((float)M_PI);//結束弧度
// 開始畫弧:CGPointMake:弧的圓心 radius:弧半徑 startAngle:開始弧度 endAngle:介紹弧度 clockwise:YES為順時針铛绰,No為逆時針
[path addArcWithCenter:CGPointMake((size.width)/2, radius) radius:radius startAngle:startAngle endAngle:endAngle clockwise:YES];
// 開始畫弧以外的部分
[path addLineToPoint:CGPointMake(size.width/2+ww, standOutHeight)];
[path addLineToPoint:CGPointMake(size.width, standOutHeight)];
[path addLineToPoint:CGPointMake(size.width,size.height)];
[path addLineToPoint:CGPointMake(0,size.height)];
[path addLineToPoint:CGPointMake(0,standOutHeight)];
[path addLineToPoint:CGPointMake(size.width/2-ww, standOutHeight)];
layer.path = path.CGPath;
layer.fillColor = [UIColor whiteColor].CGColor;// 整個背景的顏色
layer.strokeColor = [UIColor colorWithWhite:0.765 alpha:1.000].CGColor;//邊框線條的顏色
layer.lineWidth = 0.5;//邊框線條的寬
// 在要畫背景的view上 addSublayer:
[imageView.layer addSublayer:layer];
return imageView;
}
//往tabbar中添加圖片
[self.tabbar insertSubview:[self drawTabbarBgImageView] atIndex:0];
//我是自定義自己用uiview寫的一個tabbar产喉,所以直接往最下面的圖層添加圖片
[self insertSubview:[self drawTabbarBgImageView] atIndex:0];
如果是系統的tabbar可能需要去除那條分割線
參考的內容是:
轉載請注明出處:http://blog.csdn.net/boyqicheng/article/details/50723011