很多時(shí)候我們需要修改tabbaritem 點(diǎn)擊之后的樣式,selectedImage 并不能填充滿整個(gè)控件,這時(shí)候就需要我們自己繪制一張背景圖。
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;
}