IOS project development practice-customize the navigation bar and Status Bar background, and develop ios Projects
On the top of the iPhone status bar, there will be a lot of information, such as the operator, signal strength, network status, time, power, and so on. We use a lot of apps, such as QQ, and so on, and we will find that the background or images in the navigation bar have been reset, which will increase the user experience and save the screen space below. How can I set the navigation bar images?
(1) Create an iOS project and select Swift as the language. Drag an image to Images. xcassets and set the size as the background of the top navigation bar.
(2) Select ViewController in Main. storyboard and choose Editor> Embed in> Navigation Controller. Add the top Navigation bar to the interface.
(3) implement the following in the Code:
Import UIKitclass ViewController: UIViewController {override func viewDidLoad () {super. viewDidLoad () initNavBarImg ()} func initNavBarImg () {self. navigationController ?. NavigationBar. setBackgroundImage (UIImage (named: "naviBar"), forBarMetrics: UIBarMetrics. Default) self. navigationController ?. NavigationBar. topItem ?. Title = "" // if the title at the top of the navigation bar is not set, the title will disappear even if it is set in the storyboard. }}
(4) then run the program. The result is as follows: You can see that the top has been set to the desired pattern.
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.