Is it possible to have a red UIBarButtonItem?
If anyone is looking for code to exactly duplicate a simple UIBarButtonItem:
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setBackgroundImage:[UIImage imageNamed:@"delete.png"] forState:UIControlStateNormal];
[button setTitle:@"Delete" forState:UIControlStateNormal];
button.titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:12.0f];
[button.layer setCornerRadius:4.0f];
[button.layer setMasksToBounds:YES];
[button.layer setBorderWidth:1.0f];
[button.layer setBorderColor: [[UIColor grayColor] CGColor]];
button.frame=CGRectMake(0.0, 100.0, 60.0, 30.0);
[button addTarget:self action:@selector(batchDelete) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem* deleteItem = [[UIBarButtonItem alloc] initWithCustomView:button];
And delete.png is:
Why not just :
[[self editButtonItem] setTintColor:[UIColor redColor]];
(on sdk 4.* , ios 5 and up)
You can create custom UIButton with your desired look and initialize your UIBarButtonItem with it as a custom view.
UIButton *button = [UIButton buttonWithType:....];
...(customize your button)...
UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithCustomView:button];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With