RegularExpression
RegularExpression

Reputation: 3541

UIBarButtonItem Custom Icon

I use 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 here's how it looks when it is run on the simulator - a solid red square:

enter image description here

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

Any suggestions? TIA.

Upvotes: 3

Views: 6457

Answers (3)

Craig
Craig

Reputation: 9330

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

It should be created with a transparent background, like this:

Icon with transparency

i.e. in Photoshop you should be able to see the background pattern like this:

Fixed image in Photoshop

Upvotes: 3

Parth Pandya
Parth Pandya

Reputation: 1490

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

This worked for me

Upvotes: 2

Soumya Ranjan
Soumya Ranjan

Reputation: 4843

Try this one. Its working fine. I also share my output screenshot. u have to use small size of icon . but 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 output.

Upvotes: 2

Related Questions