7

我正在尝试在我的标签栏中添加一个右栏按钮navigationbar,它在 iphone 5 和 5s 设备以及所有模拟器中工作正常。但它没有出现在 iphone 6 和 6+ 设备中。但是它在 iphone 6 和 6+ 的模拟器上运行良好。

这是按钮代码。

@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");

}

您也可以在图像中看到在此处输入图像描述

还有一个清晰的 iphone 6 图像 在此处输入图像描述

看到按钮的边框为 2,甚至没有出现占位符。

4

3 回答 3

1

1) 如果您使用 Autoresizing Sub-Mask,请检查您是否正确设置了“Autoresizing Mask”,[Check in Preview]。

2) 如果您使用的是 Size 类,请确保您设置了约束,[Check in Preview]。

3)第二件事,如果它无论如何都不起作用并且您很着急,只需使用您的自定义标题视图而不是左右两侧带有自定义按钮的导航栏。

于 2015-06-29T09:38:28.450 回答
0

使用下面的代码。

 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]];
于 2015-06-30T09:37:12.593 回答
0

您可以使用视图调试(Debug View Hierarchy)来检查您的按钮在哪里消失了。只需单击调试/日志区域顶部的设备图标

于 2015-06-30T09:53:36.130 回答