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
- # Import <UIKit/UIKit. h>
- @ Interface ViewController: UIViewController
- @ End
Code in the ViewController. m file:
[Cpp]View plaincopy
- # Import "ViewController. h"
- @ Interface ViewController ()
- @ End
- @ Implementation ViewController
- -(Void) viewDidLoad
- {
- [Super viewDidLoad];
- // Do any additional setup after loading the view, typically from a nib.
- // Create a navigation bar
- UINavigationBar * navBar = [[UINavigationBar alloc] initWithFrame: CGRectMake (0, 0,320, 44)];
- // Create a navigation bar set
- UINavigationItem * navItem = [[UINavigationItem alloc] initWithTitle: nil];
- // Add the title and button to this set Item
- // Style: Set the button style. There are three options.
- // Action: @ selector: Click Event of the set button
- // Create a button on the left
- UIBarButtonItem * leftButton = [[UIBarButtonItem alloc] initWithTitle: @ "Left" style: UIBarButtonItemStyleBordered target: self action: @ selector (clickLeftButton)];
- // Create a button on the right
- UIBarButtonItem * rightButton = [[UIBarButtonItem alloc] initWithTitle: @ "right" style: UIBarButtonItemStyleDone target: self action: @ selector (clickRightButton)];
- // Set the content in the navigation bar
- [NavItem setTitle: @ "Lingling paint"];
- // Add the navigation bar set to the navigation bar and disable the animation.
- [NavBar pushNavigationItem: navItem animated: NO];
- // Add the left and right buttons to the navigation bar collection.
- [NavItem setLeftBarButtonItem: leftButton];
- [NavItem setRightBarButtonItem: rightButton];
- // Add all content in the title bar to the main view
- [Self. view addSubview: navBar];
- // Finally, release the control in the memory to avoid Memory leakage.
- [NavItem release];
- [LeftButton release];
- [RightButton release];
- }
- -(Void) showDialog :( NSString *) str
- {
- UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @ "this is a dialog box" message: str delegate: self cancelButtonTitle: @ "OK" otherButtonTitles: nil];
- [Alert show];
- [Alert release];
- }
- -(Void) clickLeftButton
- {
- [Self showDialog: @ "click the button on the left of the navigation bar"];
- }
- -(Void) clickRightButton
- {
- [Self showDialog: @ "click the button on the right of the navigation bar"];
- }
- -(Void) viewDidUnload
- {
- [Super viewDidUnload];
- // Release any retained subviews of the main view.
- }
- -(BOOL) shouldAutorotateToInterfaceOrientation :( UIInterfaceOrientation) interfaceOrientation
- {
- Return (interfaceOrientation! = UIInterfaceOrientationPortraitUpsideDown );
- }
- @ 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.