Jay
Jay

Reputation: 20136

How to remove a border from a UIButtonBarItem in an iPad navigation bar?

After creating a standard/default navigation style application, I am trying to add a reload button to a navigation bar to its "RootViewController". The following works, however adds a border to the button, which is as far as I can tell fairly non standard for iPad apps.

How do I add a button that does not have a border?

- (void)viewDidLoad {
    if (reloadButton == nil) {
        reloadButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:  UIBarButtonSystemItemRefresh target: nil action: nil];
        reloadButton.style =  UIBarButtonItemStylePlain;
        reloadButton.target = self;
        reloadButton.action = @selector(reloadRates);
        self.navigationItem.rightBarButtonItem = reloadButton;
    } 
    ....
}

Ultimately this app targets both iPhone and iPad, but I am only concerned about iPad for now.

It turns out that changing the style from UIBarButtonItemStylePlain to UIBarButtonItemStyleBordered result in the same bordered button.

Upvotes: 2

Views: 2705

Answers (2)

sPooKee
sPooKee

Reputation: 131

In XCode 4.5.2 just set the BackgroundImage of the Button to an empty Image: (buttonSetup is type of UIBarButtonItem)

[self.buttonSetup setBackgroundImage:[UIImage new] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];

Upvotes: 11

Joe
Joe

Reputation: 3761

From the iOS Human Interface Guidelines:

Plain style—For example, the Compose button in the Mail toolbar uses plain style. This style is suitable for toolbars only. In fact, if you specify the plain style for a button in the navigation bar, it is converted to the bordered style.

Most iPad apps you are seeing use a split view which has a UIToolbar at the top.

Upvotes: 5

Related Questions