I'm trying to set an image for a right bar item in my navigation controller but iOS 6 keeps showing a black glow. I have tried a number of solutions from stack overflow but can't get it to work. The current code I have is this:
UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"gear"]
style:UIBarButtonItemStylePlain
target:self
action:@selector(someMethod)];
[rightItem setImageInsets:UIEdgeInsetsMake(5, 5, 5, 5)];
[[self navigationItem] setRightBarButtonItem:rightItem];
In iOS7 is looks like this which is what I want: This is how it looks in iOS6
try this one :
UIImage *faceImage = [UIImage imageNamed:@"gear.png"];
UIButton *face = [UIButton buttonWithType:UIButtonTypeCustom];
face.bounds = CGRectMake( 10, 0, faceImage.size.width, faceImage.size.height );//set bound as per you want
[face addTarget:self action:@selector(someMethod) forControlEvents:UIControlEventTouchUpInside];
[face setImage:faceImage forState:UIControlStateNormal];
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithCustomView:face];
self.navigationItem.rightBarButtonItem = backButton;
may it will help you.
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