UIButton *btn = [UIButton buttonwithtype:uibuttontyperoundedrect];
/**
* Set Frame to control button size only
*/
Btn.frame= cgrectmake (0, 0, 40, 44);
[Btn addtarget:self Action: @selector (buttonclicked) forcontrolevents:uicontroleventtouchupinside];
Uibarbuttonitem *btn_right = [[Uibarbuttonitem alloc] initwithcustomview:btn];
Uibarbuttonitem *negativespacer = [[Uibarbuttonitem alloc]
Initwithbarbuttonsystemitem:uibarbuttonsystemitemfixedspace
Target:nil Action:nil];
/**
* Width is negative, equivalent to BTN to the right to move the width of the value of pixels, because the button itself and the boundary spacing is 5pix, so width is set to 5, the spacing is exactly adjusted
* When the 0;width is positive, the opposite is the equivalent of moving the width to the left by a number of pixels
*/
Negativespacer.width =-5;
Self.navigationItem.rightBarButtonItems = [Nsarray arraywithobjects:negativespacer, btn_right, nil];
[Btn_right release];
Adjust the spacing between Leftbarbuttonitem and rightbarbuttonitem on the navigation bar and screen boundaries