美文网首页
iOS开发笔记-35: tabbar中间凸出按钮

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

作者: 原味蛋炒饭 | 来源:发表于2017-05-16 15:17 被阅读46次

效果:


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中间凸出按钮

      本文链接:https://www.haomeiwen.com/subject/heylxxtx.html