Use of NavigationBar
1. // use the setnavigationbarhidmethod of the navigation controller to hide the navigation bar
[Self. navigationControllersetNavigationBarHidden: YES];
2. // the size of the navigation bar in the navigation controller is fixed (320*44)
3. // how to get the navigation bar
// Self. navigationController. navigationBar
4. // set the style of the navigation bar (black style, default: Defautl style, after iOS7, the remaining three styles are almost the same). Setting the Style of the navigation bar will affect the status bar
// Before iOS7, setting the navigation bar style does not affect the status bar
Self. navigationController. navigationBar. barStyle = UIBarStyleDefault;
5. // multiple applications in Development (set the background image of the navigation bar)
// UIBarMetricsDefault: iPhone portrait Mode)
// The iPhone landscape (Landscape mode) corresponding to UIBarMetricsLandscapePhone)
6. // The image size is strictly (320*44, 640*88 Retina screen) // The image size strictly complies with the 320*44 size, and the texture will not affect the status bar, the status bar automatically displays the original style.
[Self. navigationController. navigationBarsetBackgroundImage: [UIImageimageNamed: @ "navigationbar"] forBarMetrics: UIBarMetricsDefault];
// Horizontal screen navigation bar size (480*32) (Landscape mode)
[Self. navigationController. navigationBarsetBackgroundImage: [UIImageimageNamed: @ "nav-32"] forBarMetrics: UIBarMetricsLandscapePhone];
UINavigationItem (used to customize the display of content on the navigation bar)
1. // set the title displayed on the navigation bar through navigationItem
Self. navigationItem. title = @ "root ";
2. // set the title view displayed on the navigation bar
Set titleView of the navigation bar to a view
Self. navigationItem. titleView = titleView;
3. UIBarButtonItem objects can be created in multiple ways.
/// Initialize the title
/// UIBarButtonItemStylePlain (iOS7 removes all the rounded rectangle and border of the Item)
/// UIBarButtonItemStylePlain (iOS7 removes all the rounded rectangle and border of the Item)
4. ///// displayed on the left of the navigation bar
Self. navigationItem. leftBarButtonItem = item;
5. /// use the style provided by the system to initialize the UIBarButtonItem object.
UIBarButtonItem * item1 = [[UIBarButtonItemalloc] initWithBarButtonSystemItem: UIBarButtonSystemItemCameratarget: selfaction: @ selector (rightItemClicked :)];
6. // The most common method for UIBarButtonItem creation in development: initWithCustomView (receiving UIView) the most commonly used method for receiving a UIButton (custom style, texture)
UIButton * customBtn = [UIButtonbuttonWithType: UIButtonTypeCustom];
[CustomBtn setFrame: CGRectMake (0, 0, 30, 30)];
[CustomBtn setBackgroundImage: [UIImageimageNamed: @ "itemImage"] forState: UIControlStateNormal];
[CustomBtn addTarget: self action: @ selector (custombtnClicked)
ForControlEvents: UIControlEventTouchUpInside];
// The above is a custom button. The following sentence assigns the created button as a mmview to barbuttonitem.
UIBarButtonItem * item2 = [[UIBarButtonItem alloc] initWithCustomView: customBtn];
7. /// it will be displayed from right to left on the navigation bar
NSArray * array = [NSArray arrayWithObjects: item1, item2, nil];
[Item1 release];
[Item2 release];
//// The rightBarButtonItems array sets the UIBarButtonItem display. The element of the array must be the UIBarButtonItem object.
Self. navigationItem. rightBarButtonItems = array;
8. Determine whether a method exists in a class.
// Determine whether _ delegate supports sendTitle: Method
If ([class respondsToSelector: @ selector (sendTitle :)])
Toolbar (toolbar)
1. // each navigation controller has a toolbar, which is a UIToolBar object. It is displayed at the bottom and the size (320*44). The toolbar is hidden by default.
// Display the toolbar
[Self. navigationControllersetToolbarHidden: NO];
2. // UIToolbarPositionBottom (TopBar and BottomBar can be specified for each UIView). The toolbar in the navigation controller is automatically created as the BottomBar of the navigation controller view.
[Self. navigationController. toolbarsetBackgroundImage: [UIImageimageNamed: @ "toolBar.png"] forToolbarPosition: UIToolbarPositionBottombarMetrics: UIBarMetricsDefault];
3. UIBarButtonItem * item1 = [[UIBarButtonItemalloc] initWithBarButtonSystemItem: UIBarButtonSystemItemAddtarget: selfaction: @ selector (itemClicked)];
UIBarButtonItem * item2 = [[UIBarButtonItemalloc] initWithBarButtonSystemItem: UIBarButtonSystemItemEdittarget: selfaction: @ selector (itemClicked)];
// UIBarButtonSystemItemFlexibleSpace)
UIBarButtonItem * space = [[UIBarButtonItemalloc] initWithBarButtonSystemItem: UIBarButtonSystemItemFlexibleSpacetarget: selfaction: @ selector (itemClicked)];
NSArray * array = [NSArray arrayWithObjects: space, item1, space, item2, space, nil];
[Item1 release];
[Item2 release];
[Space release];
Self. toolbarItems = array;
// During development, the toolbar at the bottom is often customized through UIView + UIButton.