At the top of the iphone's status bar, there will be a lot of information, such as operator, signal strength, network status, time, power, and so on. We use a lot of apps, such as QQ, and so on, will find the navigation bar background or pictures are reset, so that can increase the user experience, but also can save the screen space below. So how do you set up a picture of a navigation bar?
(1) First build an iOS project, language select Swift. and drag a picture into the images.xcassets, set it to its own size, and use it as the background of the top navigation bar.
(2) Select Viewcontroller in Main.storyboard and select 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= "" //does not set the title at the top of the navigation bar, even if the caption is set in storyboard, it disappears. }}
(4) Then run the program, the effect is as follows: found the top has been set to the desired pattern.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
iOS project development-Custom settings navigation bar and status bar background