iOS中是否显示了额外的UINavigationBar?

问题描述 投票:0回答:2

我在使用UINavigationBar时遇到问题,当我在该处添加UIButton并运行该应用程序时,我可以在UINavigationBar的顶部看到一个额外的UINaviagtionBar覆盖。

请帮助

结构类似

UITabbarController-> UINavigationController-> UIViewController

我已附上屏幕截图链接

运行时间 [![[1]] [1]] [1]

Xcodeenter image description here

[[navigationcontroller-> viewcontroller screen] [3]

代码

ViewDidAppear()

UIImage *myImage = [UIImage imageNamed:@"filter.png"];
UIButton *myButton = [UIButton buttonWithType:UIButtonTypeCustom];
[myButton setImage:myImage forState:UIControlStateNormal];
myButton.showsTouchWhenHighlighted = YES;
myButton.frame = CGRectMake(0.0, 0.0,25,25);
[myButton addTarget:self action:@selector(refreshSection) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithCustomView:myButton];
self.navigationItem.leftBarButtonItem = rightButton;

UIImage *myImage1 = [UIImage imageNamed:@"Contacts.png"];
UIButton *myButton1 = [UIButton buttonWithType:UIButtonTypeCustom];
[myButton1 setImage:myImage1 forState:UIControlStateNormal];
myButton1.showsTouchWhenHighlighted = YES;
myButton1.frame = CGRectMake(0.0, 0.0,30,30);

[myButton1 addTarget:self action:@selector(profile) forControlEvents:UIControlEventTouchUpInside];

UIBarButtonItem *rightButton1 = [[UIBarButtonItem alloc] initWithCustomView:myButton1];
[self.navigationItem setRightBarButtonItems:[NSArray arrayWithObjects:rightButton1, nil]];

full screen storyboard

ios objective-c uinavigationcontroller uibutton uinavigationbar
2个回答
0
投票

我认为代码是正确的,只需设置contentMode属性。

[[[myButton imageView] setContentMode:UIViewContentModeScaleAspectFit];

与其他按钮相同。


0
投票

转到您的根导航控制器,选择导航栏,然后在“属性”检查器下,确保您具有:

  1. 默认样式,
  2. 启用半透明选项,
  3. 默认色条色调。
© www.soinside.com 2019 - 2024. All rights reserved.