I am trying to set an image for my UIBarButtonItem and I cannot do this. I tried twice, and in the first case I get the image in the right place, but when I click the button, nothing happens (it should pop out of a new window, but nothing works). There is a piece of code that I used:
UIImage *faceImage = [UIImage imageNamed:@"plus_button.png"]; UIButton *face = [UIButton buttonWithType:UIButtonTypeCustom]; face.bounds = CGRectMake( 0, 0, faceImage.size.width, faceImage.size.height ); [face setImage:faceImage forState:UIControlStateNormal]; UIBarButtonItem *faceBtn = [[[UIBarButtonItem alloc] initWithCustomView:face]initWithImage:faceImage style:UIBarButtonItemStylePlain target:self action:@selector(addProduct:)]; self.navigationItem.leftBarButtonItem = faceBtn;
In the second case, I set the image on the button, and a new window appears, as it should be, but not only is my custom image that I want, but it also shows βbordersβ, it looks like the image was placed in the center by default button . Obviously, I want only my image, not borders, only my image. In the second case, a code snippet is used:
UIBarButtonItem *addButton = [[UIBarButtonItem alloc]initWithImage:faceImage style:UIBarStyleDefault target:self action:@selector(addProduct:)]; self.navigationItem.leftBarButtonItem = addButton;
Please help me solve the problem, any help would be appreciated, thanks!
Evgeniy Kleban
source share