Friday, May 31, 2013

UIBarButtonItem UIBarButtonItemStyleDone example in Objective C (iOS).


UIBarButtonItem UIBarButtonItemStyleDone


UIBarButtonItemStyle
Specifies the style of a item.

typedef enum {
UIBarButtonItemStylePlain,
UIBarButtonItemStyleBordered,
UIBarButtonItemStyleDone,
} UIBarButtonItemStyle;
Constants
UIBarButtonItemStylePlain
Glows when tapped. The default item style.
UIBarButtonItemStyleBordered
A simple button style with a border.
UIBarButtonItemStyleDone
The style for a done button—for example, a button that completes some task and returns to the previous view.

UIBarButtonItem UIBarButtonItemStyleDone example.
// Set to done
editButton.style = UIBarButtonItemStyleDone;
editButton.title = @"Done";

// Set back to edit
editButton.style = UIBarButtonItemStyleBordered;
editButton.title = @"Edit";

Example of [UIBarButtonItem UIBarButtonItemStyleDone].
to change the button the Done button use this

[self.navigationItem.rightBarButtonItem setStyle:UIBarButtonItemStyleDone];
to change the button to Edit button use this

[self.navigationItem.rightBarButtonItem setStyle:UIBarButtonItemStyleBordered];

UIBarButtonItem UIBarButtonItemStyleDone example.
        NSString *title = app.settings.editing
                        ? NSLocalizedString(@"Done", @"")
                        : NSLocalizedString(@"Edit", @"");

        UIBarButtonItemStyle style  = app.settings.editing
                                    ? UIBarButtonItemStyleDone
                                    : UIBarButtonItemStyleBordered;

        UIBarButtonItem *editButton
            = [[UIBarButtonItem alloc] initWithTitle:title
                                               style:style
                                              target:self.editButton.target
                                              action:self.editButton.action];

        self.navigationItem.rightBarButtonItem = editButton;

End of UIBarButtonItem UIBarButtonItemStyleDone example article.