更改导航栏背景色以及半透明效果

直接在


func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {}


这个方法里面加上就可以了

///修改导航栏背景颜色和标题文字颜色

///导航栏背景色


let color = UIColor .whiteColor()

let bar = UINavigationBar.appearance();

bar.shadowImage = UIImage();

bar.barStyle = .Default;

bar.titleTextAttributes = [NSForegroundColorAttributeName:UIColor .blackColor()];

bar.setBackgroundImage(UIImage(color: color), forBarMetrics: UIBarMetrics.Default);

bar.translucent = true;



///封装方法


+ (UIColor *)colorWithImage:(NSString *)imageNamed{

return [UIColor colorWithPatternImage:[UIImage imageWithName:imageNamed]];

}

+ (UIImage *)imageWithName:(NSString *)name{

NSString *bundlePath = [[NSBundle mainBundle] bundlePath];

NSString *filePath = [bundlePath stringByAppendingPathComponent:name];

UIImage *img = [UIImage imageWithContentsOfFile:filePath];

return img;

}

你可能感兴趣的:(更改导航栏背景色以及半透明效果)