iOS project development-Custom settings navigation bar and status bar background

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.