我希望我的应用程序中的UINavigationBar完全透明,并在其下直接与viewcontroller刷新.但是,我能找到的唯一代码使它半透明但不透明.我知道这可以在iOS 7中完成,因为它在笔记应用程序中使用.我的问题是,他们用来做什么代码?
我想让我UINavigationBar的UINavigationController透明.我创建了一个子类,UINavigationController并喜欢它在我的storyboard文件中的一个场景.这是我的子类的一部分:
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
let size = self.navigationBar.frame.size
self.navigationBar.setBackgroundImage(imageWithColor(UIColor.blackColor(), size: size, alpha: 0.2), forBarMetrics: UIBarMetrics.Default)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func imageWithColor(color: UIColor, size: CGSize, alpha: CGFloat) -> UIImage {
UIGraphicsBeginImageContext(size)
let currentContext = UIGraphicsGetCurrentContext()
let fillRect = CGRectMake(0, 0, size.width, size.height)
CGContextSetFillColorWithColor(currentContext, color.CGColor)
CGContextSetAlpha(currentContext, alpha)
CGContextFillRect(currentContext, fillRect)
let retval: UIImage = …Run Code Online (Sandbox Code Playgroud)