我使用下面的代码将渐变颜色设置为navigationBar
。但是在应用渐变颜色后,我的表格 View 单元格滚动回导航栏,并且顶部单元格的内容在导航栏上可见。
let gradient: CAGradientLayer = CAGradientLayer()
let navigationBar = self.navigationController?.navigationBar.bounds
let statusBar = UIApplication.sharedApplication().statusBarFrame
let gradientBounds = CGRectMake(0.0, 0.0, (navigationBar?.size.width)!+statusBar.size.width, (navigationBar?.size.height)!+statusBar.size.height)
gradient.frame = (gradientBounds)
gradient.colors = [UIColor.redColor().CGColor, UIColor.blackColor().CGColor]
gradient.locations = [0.0, 1.0]
UIGraphicsBeginImageContext(gradient.bounds.size);
gradient.renderInContext(UIGraphicsGetCurrentContext()!)
let backImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
self.navigationController?.navigationBar.barStyle = UIBarStyle.Default
self.navigationController?.navigationBar.setBackgroundImage(backImage, forBarMetrics: UIBarMetrics.Default)
最佳答案
导航栏默认是半透明的,即使不是,这仍然是第一个要验证的地方。设置纯色背景图像不会使其变得不透明,此外您还需要通过代码或在 Interface Builder 中设置导航栏 translucent
属性。
关于ios - UItableviewcell 在 ios 中返回导航栏可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34009365/