7

I am trying to add a Right bar button in my tabbar's navigationbar, and its working fine in iphone 5 and 5s device and all simulators. But its not showing up in iphone 6 and 6+ device.However its working fine on simulator of iphone 6 and 6+.

Here is the button code.

@property (nonatomic, weak) UIButton *rightButton;



-(void)setNavigationBarRightButton
{


    rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
    rightButton.frame = CGRectMake(0, 0, 40, 40);
    rightButton.layer.cornerRadius = 20;
    rightButton.layer.borderColor = [[UIColor lightGrayColor] CGColor];
    rightButton.layer.borderWidth = 2;
    rightButton.imageView.layer.cornerRadius = 20;
    rightButton.clipsToBounds = YES;




    UIImage* image;

    NSData* imageData = [[NSUserDefaults standardUserDefaults] objectForKey:@"image"];


    if (imageData == (id)[NSNull null] || imageData.length == 0) {
        NSLog(@"image data is %@",imageData);
        image = [UIImage imageNamed:@"defaultIcon.png"];
    }
    else {
        image = [UIImage imageWithData:imageData];

    }

    // rightButton.imageView.image = image;
    [rightButton setBackgroundImage:image forState:UIControlStateNormal];

    [rightButton addTarget:self action:@selector(onClickrighttButton:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightButton];

    self.tabBarController.navigationItem.rightBarButtonItem = rightBarButtonItem;




}

- (void)onClickrighttButton:(id)sender
{
    NSLog(@"clicked");

}

You can see in the image as wellenter image description here

Also a clear image of iphone 6 enter image description here

See there is even no place holder appear as the button have a border of 2.

Saad Chaudhry
  • 1,392
  • 23
  • 37

3 Answers3

1

1) If you are using Autoresizing Sub-Mask check Whether you have set the 'Autoresizing Mask' properly, [Check in Preview].

2) If you are using Size class then make sure about the constraints you have set, [Check in Preview].

3) Second thing if its not working by any way and you are in hurry, Simply use your custom header view instead of navigation bar with custom buttons on right and left.

stkent
  • 19,772
  • 14
  • 85
  • 111
iShwar
  • 1,625
  • 1
  • 16
  • 31
0

Use below code.

 UIImage* searchImage = [UIImage imageNamed:@"search.png"];
 CGRect searchFraming = CGRectMake(30, 30, 25, 26);
 UIButton *searchButton = [[UIButton alloc] initWithFrame:searchFraming];
 [searchButton setBackgroundImage:searchImage forState:UIControlStateNormal];
 [searchButton addTarget:self action:@selector(searchButtonClicked)
           forControlEvents:UIControlEventTouchUpInside];
 [searchButton setShowsTouchWhenHighlighted:YES];
 UIBarButtonItem *searchButtonBarItem =[[UIBarButtonItem alloc] initWithCustomView:searchButton];
 [self.navigationItem setRightBarButtonItems:[NSArray arrayWithObjects:locationButtonBarItem ,nil]];
Raza.najam
  • 769
  • 6
  • 15
0

You can use view debugging (Debug View Hierarchy) to check, where your button is gone. Just click on the device icon on the top of your debugging / log area