首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >导航项目SWIFT的问题

导航项目SWIFT的问题
EN

Stack Overflow用户
提问于 2018-05-28 15:47:55
回答 1查看 108关注 0票数 -1

由于我需要使导航栏透明,一切正常,但现在NavBar项目得到淡出。

如何管理它呢?

代码语言:javascript
复制
override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)

    self.navigationItem.title = "Property Details"
    self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedStringKey.font: UIFont.systemFont(ofSize: 16, weight: UIFont.Weight.bold)]
    self.navigationController?.navigationBar.tintColor = UIColor.black
    self.navigationController?.navigationBar.alpha = 0.5

}

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-05-28 16:10:04

您必须在初始视图控制器上从storyboard添加导航控制器,或者每当您呈现控制器时都必须添加导航控制器。

希望这对你有用

删除alpha = 0.5,对于导航栏透明度,您需要执行以下操作:

代码语言:javascript
复制
// This is color extension to get image from color
public extension UIColor {

    func convertImage() -> UIImage {
        let rect: CGRect = CGRect(x: 0, y: 0, width: 1, height: 1)
        UIGraphicsBeginImageContext(rect.size)
        let context: CGContext = UIGraphicsGetCurrentContext()!

        context.setFillColor(self.cgColor)
        context.fill(rect)

        let image: UIImage = UIGraphicsGetImageFromCurrentImageContext()!
        UIGraphicsEndImageContext()
        return image
    }
}
///This is tranceparent image which is get from color
let image = UIColor.init(red: 255/255, green: 255/255, blue: 255/255, alpha: 0.2).convertImage()
self.navigationController?.navigationBar.setBackgroundImage(image, for: .default)

您需要在代码中添加UIColor扩展,然后在控制器中添加底部两行,您可以使用UIColor中的增加或减少alpha来调整淡入淡出的背景视图,现在我已经设置了0.2Alpha

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50561499

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档