在iOS中显示额外的UINavigationBar?

时间:2015-08-06 12:34:51

标签: ios objective-c uinavigationcontroller uibutton uinavigationbar

我对UINavigationBar有一个问题,当我在那里添加UIButton时,当我运行应用程序时,我可以在我的UINavigationBar上看到一个额外的UINaviagtionBar覆盖。

请帮忙

结构就像

UITabbarController - > UINavigationController - > UIViewController

我附上了截屏链接

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

Xcode enter image description here

[navigationcontroller-> viewcontroller屏幕] [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

2 个答案:

答案 0 :(得分:0)

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

[[myButton imageView] setContentMode:UIViewContentModeScaleAspectFit];

其他按钮相同。

答案 1 :(得分:0)

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

  1. 默认样式
  2. 启用半透明选项,
  3. 默认栏色调。