Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

As i need to make Nav Bar transparent, Everything works fine But now NavBar Items are getting fade.

How can it be manage?

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

}

enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
142 views
Welcome To Ask or Share your Answers For Others

1 Answer

You have to add navigation controller from storyboard on initial view controller or you have to add navigation controller whenever you present the controller.

Hope this will work for you

Remove alpha = 0.5 and for nav bar transparency you need to do this:

// 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)

You need to add UIColor extension in your code and then add bottom two lines in your controller and you can adjust your faded background view using increase or decrease alpha in UIColor, Now I have set 0.2 alpha


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...