Asked
Active
Viewed 2,095 times
2
-
you can keep in your navigation controller... or design your application in such a way whenever viewcontroller open it must have top view – Muhammad Shauket Jan 09 '19 at 06:45
-
elaborate your answer a little more. @ShauketSheikh – Akbar Khan Jan 09 '19 at 06:53
-
Refer this : https://stackoverflow.com/questions/38540091/subview-on-top-of-window-view-in-swift – Kuldeep Jan 09 '19 at 07:13
-
create a base controller and inherit that controller with each controller, in base controller add a view like header at top – Muhammad Shauket Jan 09 '19 at 07:14
2 Answers
0
you can use the following code to add a view to your application window
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
// Do any additional setup after loading the view, typically from a nib.
let newView = UIView()
newView.frame = CGRect(x:0,y:UIApplication.shared.statusBarFrame.height, width: view.frame.size.width, height: 30)
newView.backgroundColor = UIColor.red
let label = UILabel()
label.frame = newView.bounds
label.text = "header"
newView.addSubview(label)
UIApplication.shared.keyWindow?.addSubview(newView)
let bounds = self.navigationController!.navigationBar.bounds
self.navigationController?.navigationBar.frame = CGRect(x: 0, y: newView.frame.size.height + newView.frame.origin.y, width: bounds.width, height: bounds.height )
}
Please check and let me know if this works

Kuldeep
- 4,466
- 8
- 32
- 59

Parth Dhorda
- 712
- 1
- 8
- 32
-
this worked but there is a problem, when i dismiss the view controller and navigation controller then everything get stopped. This means i lost all the references of view controller. – Akbar Khan Jan 09 '19 at 07:10
-