iOS开发笔记-35: tabbar中间凸出按钮

效果:


iOS开发笔记-35: tabbar中间凸出按钮_第1张图片
6E25C1B5-F015-41DC-95B2-8009D531ABCF.png
#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

你可能感兴趣的:(iOS开发笔记-35: tabbar中间凸出按钮)