修改tabBarItem 点击后背景颜色

很多时候我们需要修改tabbaritem 点击之后的样式,selectedImage 并不能填充满整个控件,这时候就需要我们自己绘制一张背景图。

    CGSize indicatorImageSize =CGSizeMake(_tabbarController.tabBar.bounds.size.width/5 , _tabbarController.tabBar.bounds.size.height);
    _tabbarController.tabBar.selectionIndicatorImage = [self drawTabBarItemBackgroundUmageWithSize:indicatorImageSize];

-(UIImage *)drawTabBarItemBackgroundUmageWithSize:(CGSize)size
{
    //开始图形上下文
    UIGraphicsBeginImageContext(size);
    //获得图形上下文
    CGContextRef ctx =UIGraphicsGetCurrentContext();
    
    CGContextSetRGBFillColor(ctx,253/255.0,232/255.0, 108/255.0, 1);
    CGContextFillRect(ctx,CGRectMake(0,0, size.width, size.height));
    
    
    CGRect rect =CGRectMake(0,0, size.width, size.height);
    CGContextAddEllipseInRect(ctx, rect);
    
    CGContextClip(ctx);
    
    UIImage *image =UIGraphicsGetImageFromCurrentImageContext();
    
    [image drawInRect:rect];
    
    UIGraphicsEndImageContext();
    
    return image;
}

你可能感兴趣的:(修改tabBarItem 点击后背景颜色)