1
votes

alt text

Hi!I have used UIBarButton Image but i have got such kind of issue.i mean Image+button on backside.for that i have written code below.

UIBarButtonItem *btnMap = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"mapbutton.png"] style:UIBarButtonItemStylePlain target:self action:@selector(btnMapClicked:)]; self.navigationItem.rightBarButtonItem = btnMap; [btnMap release];

1

1 Answers

1
votes

Use initWithCustomView and set a UIButton as the customView instead:

UIButton *subBtn = [UIButton buttonWithType:UIButtonTypeCustom];
subBtn.frame = CGRectMake(0, 0, 50, 40);  //adjust as needed
[subBtn setImage:[UIImage imageNamed:@"mapbutton.png"] forState:UIControlStateNormal];
[subBtn addTarget:self action:@selector(btnMapClicked:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *btnMap = [[UIBarButtonItem alloc] initWithCustomView:subBtn];
self.navigationItem.rightBarButtonItem = btnMap; 
[btnMap release];

Note that the sender in btnMapClicked: will now be a UIButton instead of a UIBarButtonItem.