Here is the snapshot:
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:)
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.
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.
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];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With