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

6 data analysis tools that you must know for operations, free and practical!

Communities , official accounts, product promotio...

CG technology brings Paul Walker back to life in Fast and Furious 7

Along with the collision of a red Ferrari and a g...

5 steps to teach you how to warn users about churn and effectively recall them

In user operations , in addition to the important...

Using Cocoa Layout Instrument to inspect automatic layout

Some time ago, MarkD discussed with us many usefu...

WeChat and Alipay announce major changes

[[428363]] Good news! WeChat and Alipay announced...

2022 Marketing Strategy Trend Report!

In 2021, the local recurrence of the epidemic has...

A major upgrade? iPhone XS has so many problems

There's no doubt that the iPhone XS and iPhon...

How to mine long-tail keywords? Fifteen methods for mining long-tail keywords

Introduction: I have been engaged in SEO website ...

Augmented reality prospects: Can Microsoft HoloLens herald the future?

Many people were shocked after watching the Micro...