Thomas Clayson
Thomas Clayson

Reputation: 29925

Indent back button on UINavigationBar?

Is there any way to indent the default back button on a UINavigationBar? Basically I just want to move it about 10pts right.

Thanks

Upvotes: 1

Views: 1271

Answers (4)

jamie-wilson
jamie-wilson

Reputation: 1925

If anyone comes across this thread and is using iOS5, this seemed to work for me:

[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(-1.0f, 0.0f) forBarMetrics:UIBarMetricsDefault];

Upvotes: 0

iTukker
iTukker

Reputation: 2083

Hiding the default back button worked for me, using a UIButton which you can style anyway you want:

...
UIBarButtonItem *backButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
UIBarButtonItem *fixedspace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
fixedspace.width = 10.0f;

self.navigationItem.leftBarButtonItems = [NSArray arrayWithObjects:fixedspace, backButtonItem, nil];
...

Upvotes: 3

Warrior
Warrior

Reputation: 39374

Better hide the default back button and add a custom back button on the navigation bar.

All the Best.

Upvotes: 2

Pieter Jongsma
Pieter Jongsma

Reputation: 3373

I don't think there is an easy way. But you could get the navigation bar object:

UINavigationBar *navBar = [navController navigationBar];

...and maybe iterate through it's subviews. I presume you could determine which subview is the back button based on it's frame property.

Upvotes: 0

Related Questions