Six tips on the navigation bar and six tips on the navigation bar
UINavigationBar
AndUINavigationItem
Is a common control in iOS development. Today I will introduce you to the six tips on the navigation bar.
1. Set the navigation bar title
Self. title = @ "iOS development: iOSDevTip ";
2. Set the navigation bar style
Setting method:
[self.navigationController.navigationBar setBarStyle:UIBarStyleBlack];
UIBarStyle
Style:
typedef NS_ENUM(NSInteger, UIBarStyle) { UIBarStyleDefault = 0, UIBarStyleBlack = 1, UIBarStyleBlackOpaque = 1, // Deprecated. Use UIBarStyleBlack UIBarStyleBlackTranslucent = 2, // Deprecated. Use UIBarStyleBlack and set the translucent property to YES};
UIBarStyleDefault
Is the default style,UIBarStyleBlack
It is black and opaque.UIBarStyleBlackOpaque
AndUIBarStyleBlackTranslucent
The two are obsolete.
To set the transparent navigation bar, add the following code:
self.navigationController.navigationBar.translucent = YES;
3. Modify the return button title
self.navigationItem.title = @"test";
4. Hide the title of the return button
The stupid method is:
self.navigationItem.title = @"";
You can also set it as follows:
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60) forBarMetrics:UIBarMetricsDefault];
5. Set leftBarButtonItem
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"back" style:UIBarButtonItemStylePlain target:self action:@selector(back:)];- (void)back:(id)sender{ [self.navigationController popViewControllerAnimated:YES];}
6. What should I do if the returned gesture is invalid when I slide left?
If you setleftBarButtonItem
After that, the left slide returns the gesture to become invalid. SetUIGestureRecognizerDelegate
Proxy:
self.navigationController.interactivePopGestureRecognizer.delegate = self;
The above are six tips on the navigation bar. For more iOS development-related technologies, please pay attention to my public account iOS development:IOSDevTip
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.