Six tips for navigation bars

Six tips for navigation bars

`UINavigationBar` and `UINavigationItem` are commonly used controls in iOS development. Today I will introduce six tips about the navigation bar.

1. Set the navigation bar title

self.title=@"iOS Development: iOSDevTip";
2. Set the navigation bar style

How to set it up:

[self.navigationController.navigationBarsetBarStyle:UIBarStyleBlack];

`UIBarStyle` style:

typedefNS_ENUM(NSInteger,UIBarStyle){

UIBarStyleDefault = 0,

UIBarStyleBlack = 1,

UIBarStyleBlackOpaque =1,//Deprecated.UseUIBarStyleBlack

UIBarStyleBlackTranslucent=2,//Deprecated.UseUIBarStyleBlackandsetthetranslucentpropertytoYES

};

`UIBarStyleDefault` is the default style, `UIBarStyleBlack` is black and opaque. `UIBarStyleBlackOpaque` and `UIBarStyleBlackTranslucent` are already deprecated.

If you want to set the navigation bar transparent, you can add the following code:

self.navigationController.navigationBar.translucent=YES;
3. Modify the back button title

self.navigationItem.title=@"test";
4. Hide the back button title

The dumber way is:

self.navigationItem.title=@"";

You can also set it like this:

[[UIBarButtonItemappearance]setBackButtonTitlePositionAdjustment:UIOffsetMake(0,-60)forBarMetrics:UIBarMetricsDefault];
5. Set leftBarButtonItem

self.navigationItem.leftBarButtonItem=[[UIBarButtonItemalloc]initWithTitle:@"back"style:UIBarButtonItemStylePlaintarget:selfaction:@selector(back:)];

-(void)back:(id)sender

{

[self.navigationControllerpopViewControllerAnimated:YES];

}

6. What to do if the left swipe back gesture fails

If you set `leftBarButtonItem` as in the previous step, the left swipe back gesture will be invalid. Just set the `UIGestureRecognizerDelegate` proxy:

self.navigationController.interactivePopGestureRecognizer.delegate=self;

The above are six tips about the navigation bar. For more iOS development related technologies, please follow my WeChat public account iOS Development: **iOSDevTip**

<<:  Technical interview strategies worth reading

>>:  Java's concise way

Recommend

Brands must do these 5 things to stand out!

I believe that many people who do brand marketing...

One solution for all event promotion plans!

Every time I organize an event, I have to write a...

How to correctly place ads on TikTok?

1 Behind the TikTok phenomenon As of mid-June 201...

Data statistics interface - interface analysis data interface

WeChat public platform launched an invitation-bas...

What are the things to pay attention to when recruiting app developers?

Recruitment is a difficult task for many companie...

Practical Guide to Community Building and Operation

The next part of the practical guide to community...

If you pick up a stone on the road, how do you tell if it is a meteorite?

The price of a good quality stone on Earth can be...

It only costs $50 to crack an iPhone!

In the past, the Israeli company Cellebrite could...

Two major channels for Tik Tok to get free traffic!

There is always not enough traffic for the video,...