【问题标题】:UINavigationBar set image not completely drawnUINavigationBar 设置图像未完全绘制
【发布时间】:2016-08-29 16:41:53
【问题描述】:

我正在尝试将图像设置为导航栏的 ViewController, 在将其设置为未完全绘制到 NavigationBar 之后。 无法理解为什么会这样。

图片尺寸为90高宽750

可以告诉我我需要做什么吗?

[self.navigationController setToolbarHidden:YES animated:NO];
self.title = NSLocalizedString(@"Dashboar", @"Dashboard");
self.navigationController.navigationBar.barTintColor = [UIColor whiteColor];
self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName : [UIColor whiteColor]};
UIImage *currentImage =  [[UIImage imageNamed:@"bg.png"]
                          resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0) resizingMode:UIImageResizingModeStretch];
[self.navigationController.navigationBar setBackgroundImage:currentImage forBarMetrics:UIBarMetricsDefault]; 

【问题讨论】:

  • 如果改变导航栏的半透明属性会改变什么吗?
  • @TejaNandamuri 谢谢,它启用我让它禁用它的工作。

标签: ios objective-c uiviewcontroller uinavigationcontroller


【解决方案1】:
[self.navigationController setToolbarHidden:YES animated:NO];
self.title = NSLocalizedString(@"Dashboar", @"Dashboard");
self.navigationController.navigationBar.barTintColor = [UIColor whiteColor];
self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName : [UIColor whiteColor]};

您必须为多个设备设置此背景图像的确切宽度。

if (IS_IPHONE4) {
[navController.navigationBar setBackgroundImage:[UIImage imageNamed:@"TopBar_iphone4.png"] forBarMetrics:UIBarMetricsDefault];
}
if (IS_IPHONE5) {
[navController.navigationBar setBackgroundImage:[UIImage imageNamed:@"TopBar_iphone5.png"] forBarMetrics:UIBarMetricsDefault];
}
if (IS_IPHONE6) {
[navController.navigationBar setBackgroundImage:[UIImage imageNamed:@"TopBar_iphone6.png"] forBarMetrics:UIBarMetricsDefault];
}
if (IS_IPHONE6Plus) {
[navController.navigationBar setBackgroundImage:[UIImage imageNamed:@"TopBar_iphone6plus.png"] forBarMetrics:UIBarMetricsDefault];
 }
   [[UINavigationBar appearance] setBackgroundImage:NavigationPortraitBackground forBarMetrics:UIBarMetricsDefault];

我必须检查此代码是否适合我。

【讨论】:

    【解决方案2】:

    貌似是半透明问题,从iOS 7+开始,默认半透明属性为YES。通过

    禁用它
       self.navigationBar.translucent = NO;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-06-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-10
      相关资源
      最近更新 更多