Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I change the position of navigationbar item?

Tags:

Here is the snapshot: enter image description here

And the code is here:

UIButton *leftButton = [UIButton buttonWithType:UIButtonTypeCustom]; leftButton.frame = CGRectMake(0.0f, 0.0f, 46.0f, 32.0f); [leftButton setBackgroundImage:[UIImage imageNamed:@"navi_register_up.png"] forState:UIControlStateNormal]; [leftButton addTarget:self action:@selector(doRegister) forControlEvents:UIControlEventTouchUpInside];  UIBarButtonItem *leftBarItem = [[UIBarButtonItem alloc] initWithCustomView:leftButton]; self.navigationItem.leftBarButtonItem = leftBarItem; [leftBarItem release]; 

Is there any way to move the button up some px? Thank you:)

like image 486
理想评论学派 Avatar asked Mar 26 '12 02:03

理想评论学派


People also ask

Can you change the navigation bar on Iphone?

Change the Bar StyleA user changes the navigation bar's style, or UIBarStyle , by tapping the “Style” button to the left of the main page. This button opens an action sheet where users can change the background's appearance to default, black-opaque, or black- translucent.

How do I customize the navigation bar in Swift?

Go to the ViewController. swift file and add the ViewDidAppear method. a nav helper variable which saves typing. the Navigation Bar Style is set to black and the tint color is set to yellow, this will change the bar button items to yellow.


1 Answers

You need to create a UIBarButtonItem with system item UIBarButtonSystemItemFixedSpace with -5 width which will remove 5 px padding. Then set leftBarButtonItems with both fixed space item and your back bar item like this -

UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil]; [negativeSpacer setWidth:-5];  self.navigationItem.leftBarButtonItems = [NSArray arrayWithObjects:negativeSpacer,leftBarItem,nil]; 
like image 84
saadnib Avatar answered Oct 19 '22 17:10

saadnib