Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Right bar button not appearing in iphone 6 and 6+

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.

like image 883
Saad Chaudhry Avatar asked Jun 29 '15 08:06

Saad Chaudhry


1 Answers

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.

like image 168
iShwar Avatar answered Oct 21 '22 11:10

iShwar