I want the bar button item in the navigation bar to be placed at the extreme corner of the navigation bar

When i try the following code, the bar-button comes with about 30px spacing from the edge,

But i want it to be just 2 pixels away from the edge. Any way to do so?

I want the bar button only, and not a custom UIButton.

UIImage* buttonImage = [UIImage imageNamedH568: @"publish_button.png"];

UIButton * clearButton = [UIButton buttonWithType: UIButtonTypeCustom];

clearButton.frame           = CGRectMake(244.0f, 5.0f, 65.0f, 33.0f);
clearButton.titleLabel.font = [Utils helveticaBoldFontOfSize: 12.0f];

[clearButton setBackgroundImage: buttonImage                        forState: UIControlStateNormal];
[clearButton setTitle:           NSLocalizedString(@"Clear", nil) forState: UIControlStateNormal];
[clearButton setTitleColor:      [UIColor whiteColor]               forState: UIControlStateNormal];

[clearButton addTarget: self action: @selector(clearNotificationsList:) forControlEvents: UIControlEventTouchUpInside];

UIBarButtonItem* clearItem = [[UIBarButtonItem alloc] initWithCustomView: clearButton];

self.navigationItem.rightBarButtonItem = clearItem;


Added the following two function from UINavigationItem-iOS7Spacing

 - (UIBarButtonItem *)spacer
    UIBarButtonItem *space = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
    space.width = -11;
    return space;

- (BOOL)isIOS7
    return ([[[UIDevice currentDevice] systemVersion] compare:@"7" options:NSNumericSearch] != NSOrderedAscending);

And then used the following inside loadView -

 UIBarButtonItem* clearItem = [[UIBarButtonItem alloc] initWithCustomView: clearButton];

    if ([self isIOS7]) {
        self.navigationItem.rightBarButtonItems = @[[self spacer],clearItem];
        self.navigationItem.rightBarButtonItem = clearItem;

Worked Flawlessly

Thank you all for your help!

Need Your Help

Java: Some form elements are partially covered by others

java swing jframe layout-manager

I designed a form for showing a graph and table inside a frame. Here is the code:

Site on two different servers

server synchronization

Im considering taking web server from China to reduce site loading times from China/China users. Problem is, how to sync/keep same data between two sites? When editing content in the site it should