UIBarButtonItem custom icon

I am using the following line to create a UIBarButtonItem with a custom icon named import2x.png:

UIBarButtonItem *btnImport = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"import2x.png"] style:UIBarButtonItemStylePlain target:self action:@selector(btnImport)];


The icon is a png that looks like this:

enter image description here

But this is what it looks like when it runs on the simulator - a solid red square:

enter image description here

The icon is created using a transparent (alpha = 0) background.

Any suggestions? TIA.


source to share

3 answers

The image in the provided link has an opaque background. If it's the same image, you're using why it looks like a solid block.

It should be created with a transparent background, for example:

Icon with transparency

i.e. in Photoshop, you should see a background image like this:

Fixed image in Photoshop



Try it. His work is wonderful. I am also sharing my screenshot. u should use small icon size. but the icon should be visible, no problem.

 UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"Login-pin.png"] landscapeImagePhone:[UIImage imageNamed:@"Login-pin.png"] style:UIBarButtonItemStylePlain target:self action:@selector(PickerCancelClick:)];


enter image description here

The search image is my conclusion.



self.navigationItem.rightBarButtonItem =  [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"g122.png"] style:UIBarButtonItemStylePlain target:self action:@selector(menuClieckd:)];


This worked for me



All Articles