iOS开发修改或删除UITabbar顶部线的颜色小技巧(即修改图片颜色的方法)

修改或删除UITabbar顶部线的颜色
1.setBackgroundImage // 背景颜色
2.setShadowImage //阴影颜色
就是修改图片颜色,以下我写了个类目
UIImage+ImageColor.h

#import 
@interface UIImage (ImageColor)
+ (UIImage *)imageWithColor:(UIColor *)color size:(CGSize)size;
@end

UIImage+ImageColor.m

#import "UIImage+ImageColor.h"
@implementation UIImage (ImageColor)
+ (UIImage *)imageWithColor:(UIColor *)color size:(CGSize)size {
    if (!color || size.width <= 0 || size.height <= 0) return nil;
    CGRect rect = CGRectMake(0.0f, 0.0f, size.width, size.height);
    UIGraphicsBeginImageContextWithOptions(rect.size, NO, 0);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context, color.CGColor);
    CGContextFillRect(context, rect);
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
}
@end

RootTabBarController.h

#import "RootTabBarController.h"
#import "UIImage+ImageColor.h"
@interface RootTabBarController ()
@end
@implementation RootTabBarController
- (void)viewDidLoad {
    [super viewDidLoad];
       ...........
    [self.tabBar setBackgroundImage:[UIImage imageWithColor:[UIColor colorWithRed:0.97 green:0.97 blue:0.99 alpha:1.00] size:CGSizeMake(self.view.frame.size.width, .5)]];
    [self.tabBar setShadowImage:[UIImage imageWithColor:[UIColor colorWithRed:0.87 green:0.88 blue:0.90 alpha:1.00] size:CGSizeMake(self.view.frame.size.width, .5)]];
}

你可能感兴趣的:(iOS开发修改或删除UITabbar顶部线的颜色小技巧(即修改图片颜色的方法))