Friday, May 31, 2013

UIBarButtonItem UIBarButtonItemStylePlain example in Objective C (iOS).


UIBarButtonItem UIBarButtonItemStylePlain


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 UIBarButtonItemStylePlain example.
UIImage *backButtonImage = [UIImage imageNamed:@"backbutton.png"];
UIBarButtonItem *customItem = [[UIBarButtonItem alloc] initWithImage:backButtonImage style:UIBarButtonItemStylePlain target:self.navigationController action:@selector(popViewControllerAnimated:)];
[self.navigationController setHidesBackButton:YES];
[self.navigationItem setLeftBarButtonItem: customItem];
[customItem release];

Example of [UIBarButtonItem UIBarButtonItemStylePlain].
- (IBAction)toggleEdit {
    BOOL editing = !self.tableView.editing;
    self.navigationItem.rightBarButtonItem.enabled = !editing;
    if (editing) {
   self.navigationItem.leftBarButtonItem.title = NSLocalizedString(@"Done", @"Done");
   //Added in the edition for this button has the same color of the UIBarButtonSystemItemDone
   self.navigationItem.leftBarButtonItem.style = UIBarButtonItemStyleDone;
}
else{
   self.navigationItem.leftBarButtonItem.title = NSLocalizedString(@"Edit", @"Edit");
   //Added in the edition for this button has the same color of the UIBarButtonSystemItemDone
   self.navigationItem.leftBarButtonItem.style = UIBarButtonItemStylePlain;
}
    [self.tableView setEditing:editing animated:YES];

UIBarButtonItem UIBarButtonItemStylePlain example.
-(IBAction) editToggle:(id) sender {

if (self.tableViewOutlet.isEditing == NO) {

    self.editOutlet.title = NSLocalizedString(@"Done", @"Done");
    self.editOutlet.style = UIBarButtonItemStyleDone;
    [self.tableViewOutlet setEditing:YES animated:YES];

}else {
    self.editOutlet.title = NSLocalizedString(@"Edit", @"Edit");
    self.editOutlet.style = UIBarButtonItemStylePlain;
    [self.tableViewOutlet setEditing:NO animated:YES];

    }
}

End of UIBarButtonItem UIBarButtonItemStylePlain example article.