How to Use the IOS navigation bar

Source: Internet
Author: User

How to Use the IOS navigation bar

This article uses pure code to implement the effect of a navigation bar. Click the button to generate an event. The basic idea is:

1. Create a navigation bar (UINavigationBar object)

2. Create a navigation bar set (UINavigationItem object)

3. Create a button on the left and a button on the right (UIBarButtonItem object), and implement corresponding event methods.

4. Add the navigation bar set to the navigation bar and disable the animation.

5. Add the left and right buttons to the navigation bar collection.

6. display the currently created navigation bar in the view

 

The specific implementation code is as follows:

The code in ViewController. h file does not need to be changed, as shown below:

 

[Cpp]View plaincopy
  1. # Import <UIKit/UIKit. h>
  2. @ Interface ViewController: UIViewController
  3. @ End

 

Code in the ViewController. m file:

 

[Cpp]View plaincopy
  1. # Import "ViewController. h"
  2. @ Interface ViewController ()
  3. @ End
  4. @ Implementation ViewController
  5. -(Void) viewDidLoad
  6. {
  7. [Super viewDidLoad];
  8. // Do any additional setup after loading the view, typically from a nib.
  9. // Create a navigation bar
  10. UINavigationBar * navBar = [[UINavigationBar alloc] initWithFrame: CGRectMake (0, 0,320, 44)];
  11. // Create a navigation bar set
  12. UINavigationItem * navItem = [[UINavigationItem alloc] initWithTitle: nil];
  13. // Add the title and button to this set Item
  14. // Style: Set the button style. There are three options.
  15. // Action: @ selector: Click Event of the set button
  16. // Create a button on the left
  17. UIBarButtonItem * leftButton = [[UIBarButtonItem alloc] initWithTitle: @ "Left" style: UIBarButtonItemStyleBordered target: self action: @ selector (clickLeftButton)];
  18. // Create a button on the right
  19. UIBarButtonItem * rightButton = [[UIBarButtonItem alloc] initWithTitle: @ "right" style: UIBarButtonItemStyleDone target: self action: @ selector (clickRightButton)];
  20. // Set the content in the navigation bar
  21. [NavItem setTitle: @ "Lingling paint"];
  22. // Add the navigation bar set to the navigation bar and disable the animation.
  23. [NavBar pushNavigationItem: navItem animated: NO];
  24. // Add the left and right buttons to the navigation bar collection.
  25. [NavItem setLeftBarButtonItem: leftButton];
  26. [NavItem setRightBarButtonItem: rightButton];
  27. // Add all content in the title bar to the main view
  28. [Self. view addSubview: navBar];
  29. // Finally, release the control in the memory to avoid Memory leakage.
  30. [NavItem release];
  31. [LeftButton release];
  32. [RightButton release];
  33. }
  34. -(Void) showDialog :( NSString *) str
  35. {
  36. UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @ "this is a dialog box" message: str delegate: self cancelButtonTitle: @ "OK" otherButtonTitles: nil];
  37. [Alert show];
  38. [Alert release];
  39. }
  40. -(Void) clickLeftButton
  41. {
  42. [Self showDialog: @ "click the button on the left of the navigation bar"];
  43. }
  44. -(Void) clickRightButton
  45. {
  46. [Self showDialog: @ "click the button on the right of the navigation bar"];
  47. }
  48. -(Void) viewDidUnload
  49. {
  50. [Super viewDidUnload];
  51. // Release any retained subviews of the main view.
  52. }
  53. -(BOOL) shouldAutorotateToInterfaceOrientation :( UIInterfaceOrientation) interfaceOrientation
  54. {
  55. Return (interfaceOrientation! = UIInterfaceOrientationPortraitUpsideDown );
  56. }
  57. @ End

What is the special and outstanding design of the navigation bar (nav bar) for iOS apps?

The overall style is very concise. Like Metro, fine fonts also play an important role in Jetsetter navigation. The navigation bar cleverly integrates the product Logo (displayed on the homepage of each topic), the loaded chrysanthemum (displayed during the transfer), and the buttons on the returned topic homepage, all are black circles as the background, and there is a smooth flip effect during the transition. 500px has never liked the drop-down box control. Hiding the function in an unknown menu is not very good. However, using the drop-down box on the navigation bar of the App 500px is a good design. Because he grabbed the user's need to go to the App as a graph-based user, and put complicated but not especially necessary navigation to the top navigation bar, and then appeared in the form of a drop-down box, compared with the traditional navigation bar, adding a Tab bar can save a little space, ensuring that users can easily access the App as soon as they open it. The form of this navigation bar (Logo/return + current page type icon/Avatar + title text) is also consistent in the detailed page at the end.
The biggest feature of Linkedin is the "Triangle". No matter which page you choose, you only need to identify the Logo or the triangle under the title and click it to go back to the homepage.
The SparrowSparrow navigation bar also has a small triangle design. However, this is under the title of the e-mail interface with a dialog, and its function is different from that of Linkedin. It is used to switch the current email interface and the dialog record list. In the mail list interface, that is, the home page, the navigation bar supports slide Gestures/clicks to switch between Inbox, Unread, And Starred. At first glance, I thought the three dots under Inbox were too small to see clearly, but I knew it as soon as I thought. There were three items in total, so I was not worried that users could not find where they were, the main function is to let users who are used to this form know that the title bar supports gesture sliding.
Gmail's navigation bar is special... You can use an iPhone to run Android applications. Do you think I don't know you if you have a triangle vest from the original three to the present? Hahaha

How to use navigation for a map of ios613

What navigation do you mean? The map navigation is third-party navigation.

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.