简体   繁体   中英

Navigation Bar back button action performing even after the button also

It is looks like a very simple question But i do not know where the mistake is. I have an navigation bar i am placing a custom nav bar back button The action is performed through out the "pink" color as shown in the image below

在此处输入图片说明

My code is below:

//-------back button  start
    UIImage *myImage1 = [UIImage imageNamed:@"Back.png"];
    UIButton *myButton1 = [UIButton buttonWithType:UIButtonTypeCustom];
    [myButton1 setImage:myImage1 forState:UIControlStateNormal];
    myButton1.showsTouchWhenHighlighted = YES;
    myButton1.frame = CGRectMake(0.0, 3.0, 40,30);
    [myButton1 addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithCustomView:myButton1];
    self.navigationItem.leftBarButtonItem = leftButton;
    //-------back button  end

I tried even this way also like "myButton1.frame = CGRectMake(0.0, 3.0, 20,30);"

Even i tried by changing the button width and height also. Then it is decreasing the width of the back button only .

Thanks in advance

You can set your button size as image size.

myButton1.frame = CGRectMake(0.0, 0.0, 30.0,30.0);  

And please check that you don't have any shadow and transparency around image.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM