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

New media planning and event operation tool library!

Marketing operations are inseparable from activit...

A step-by-step guide to spam filtering with Python and Scikit-Learn

[[197427]] Text mining (getting information from ...

How to do a good job in event operation planning process?

The essence of an event is communication, but the...

What exactly is the mysterious creature “Water Monkey”?

In our country, various versions of the "wat...

iOS fluid layout UI framework CocoaUI is open source!

CocoaUI is a powerful iOS UI framework that uses ...

New ways to operate e-commerce on Double Eleven 2019!

Recently, many of my friends in the product field...

Bidding skills and advantages of Toutiao oCPM advertising!

Many advertisers may have heard about oCPM biddin...

Salted duck eggs will "ooze oil", where does this oil come from?

Salted duck eggs, as the name suggests, are a kin...

How to trigger user growth? (The most complete mind map)

In fact, user growth is very common in our lives....

APP online promotion activity plan

APP online promotion activities refer to activiti...