ios7 navigationbar 设置背景图片引发的问题

LIUSIYU641 2014-11-03 05:06:03
之前的navigationbar 没有设置背景图片,现在要求设置背景图片,图片大小640*128 设置后模拟器显示正常,但是真机上显示的却向下移动了64,如果背景图片是640*88模拟器和真机都正确,如果不设置背景图片显示也是正确的,请问为什么会出现这种问题,怎么解决
...全文
12676 29 打赏 收藏 转发到动态 举报
写回复
用AI写文章
29 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_34282516 2016-07-12
  • 打赏
  • 举报
回复
为什么把导航栏图片透明度设置为99%就可以了
baidu_34573777 2016-04-12
  • 打赏
  • 举报
回复
self.navigationController.navigationBar.translucent = NO; self.automaticallyAdjustsScrollViewInsets = NO; 我加了这个就行了。在viewDidLoad里面,你们可以试试
qq_34126027 2016-03-23
  • 打赏
  • 举报
回复
遇到了同样的情况,不知道该怎么解决
qq_34365541 2016-03-20
  • 打赏
  • 举报
回复
我也遇到了,怎么解决的,,,,图片怎么设置%99透明度
PerfectTightwad 2015-05-11
  • 打赏
  • 举报
回复
/* New behavior on iOS 7. Default is YES. You may force an opaque background by setting the property to NO. If the navigation bar has a custom background image, the default is inferred from the alpha values of the image—YES if it has any pixel with alpha < 1.0 If you send setTranslucent:YES to a bar with an opaque custom background image it will apply a system opacity less than 1.0 to the image. If you send setTranslucent:NO to a bar with a translucent custom background image it will provide an opaque background for the image using the bar's barTintColor if defined, or black for UIBarStyleBlack or white for UIBarStyleDefault if barTintColor is nil. */ @property(nonatomic,assign,getter=isTranslucent) BOOL translucent NS_AVAILABLE_IOS(3_0); // Default is NO on iOS 6 and earlier. Always YES if barStyle is set to UIBarStyleBlackTranslucent
人鱼呢喃 2015-01-20
  • 打赏
  • 举报
回复
引用 23 楼 LIUSIYU641 的回复:
恩 ,谢谢又提供了一种方法,我自己解决了 把图片换成有99%透明度就好了,谢谢你们的回答
现在知道是什么原因引起的了么???
LIUSIYU641 2014-11-05
  • 打赏
  • 举报
回复
恩 ,谢谢又提供了一种方法,我自己解决了 把图片换成有99%透明度就好了,谢谢你们的回答
ldl0602 2014-11-04
  • 打赏
  • 举报
回复
我之前给ipad的导航栏添加Logo就这么加的。。
ldl0602 2014-11-04
  • 打赏
  • 举报
回复
这个方法,你试一下,把后面的换成你的uiimageVIew [self.navigationController.view addSubview:<#(UIView *)#>];
LIUSIYU641 2014-11-04
  • 打赏
  • 举报
回复
引用 17 楼 zhangao0086 的回复:
设置tintColor是肯定没有问题的,可以试试下面这个方法

[[UINavigationBar appearance] setBarTintColor:[UIColor colorWithPatternImage:image]]
设置后不显示图片,显示白色导航条
LIUSIYU641 2014-11-04
  • 打赏
  • 举报
回复
引用 13 楼 zhangao0086 的回复:
[quote=引用 12 楼 LIUSIYU641 的回复:] [quote=引用 10 楼 zhangao0086 的回复:] [quote=引用 9 楼 LIUSIYU641 的回复:] [quote=引用 7 楼 LIUSIYU641 的回复:] [quote=引用 5 楼 LIUSIYU641 的回复:] [quote=引用 4 楼 zhangao0086 的回复:] 你用什么方式设置navigationBar的背景图的?
在appdelegate中使用 [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"title_bar_bg"] forBarMetrics:UIBarMetricsDefault]; 模拟器是7.0的真机是7.1的不知道为什么会发生这种情况,不添加这段代码,真机模拟器都是好的[/quote] 加了的,只有高清图片[/quote] 这个设置过了 但是我随便找了一张低分辨率的图(443*273)模拟器和手机都可以了,还是不明白为什么会发生这种情况 郁闷了一下午了[/quote] 手动把navigationBar的translucent设为YES呢[/quote] 我试了一下,同样都是640*128的图片只是resolution不同一个是72pixels/inch一个是326 pixels/inch 72的就是好的 326的就出现问题[/quote] 有可能是图片本身的问题[/quote] 重新做了一张72分辨率的,但还是不行 不知道这张png图片为什么会造成这样的问题
LIUSIYU641 2014-11-04
  • 打赏
  • 举报
回复
引用 15 楼 ldl0602 的回复:
我把我的代码贴给你,你看看,应该能解决。 #define COLOR(R,G,B,A) [UIColor colorWithRed:R/255.0 green:G/255.0 blue:B/255.0 alpha:A] #define IOS_VERSION [[UIDevice currentDevice] deviceVersion] //1.设置导航栏背景颜色 if (IOS_VERSION >= 7.0) { [[UINavigationBar appearance] setBarTintColor:COLOR(2.0,129.0,222.0,1.0)]; }else{ UINavigationBar *navBar = self.navigationController.navigationBar; //if iOS 5.0 - 6.0 [navBar setBackgroundImage:[UIImage imageNamed:@"padNavigationBar.png"] forBarMetrics:UIBarMetricsDefault]; }
我的支持ios7以上的版本,没有进行版本适配
Bannings 2014-11-04
  • 打赏
  • 举报
回复
设置tintColor是肯定没有问题的,可以试试下面这个方法

[[UINavigationBar appearance] setBarTintColor:[UIColor colorWithPatternImage:image]]
ldl0602 2014-11-04
  • 打赏
  • 举报
回复
至于它具体的起始位置,你可以通过宏定义,做一个版本适配。
ldl0602 2014-11-04
  • 打赏
  • 举报
回复
我把我的代码贴给你,你看看,应该能解决。 #define COLOR(R,G,B,A) [UIColor colorWithRed:R/255.0 green:G/255.0 blue:B/255.0 alpha:A] #define IOS_VERSION [[UIDevice currentDevice] deviceVersion] //1.设置导航栏背景颜色 if (IOS_VERSION >= 7.0) { [[UINavigationBar appearance] setBarTintColor:COLOR(2.0,129.0,222.0,1.0)]; }else{ UINavigationBar *navBar = self.navigationController.navigationBar; //if iOS 5.0 - 6.0 [navBar setBackgroundImage:[UIImage imageNamed:@"padNavigationBar.png"] forBarMetrics:UIBarMetricsDefault]; }
ldl0602 2014-11-04
  • 打赏
  • 举报
回复
能发个截图吗,我看下效果。。说不定能解决。前几天,做过了版本适配了。。
Bannings 2014-11-03
  • 打赏
  • 举报
回复
引用 12 楼 LIUSIYU641 的回复:
[quote=引用 10 楼 zhangao0086 的回复:] [quote=引用 9 楼 LIUSIYU641 的回复:] [quote=引用 7 楼 LIUSIYU641 的回复:] [quote=引用 5 楼 LIUSIYU641 的回复:] [quote=引用 4 楼 zhangao0086 的回复:] 你用什么方式设置navigationBar的背景图的?
在appdelegate中使用 [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"title_bar_bg"] forBarMetrics:UIBarMetricsDefault]; 模拟器是7.0的真机是7.1的不知道为什么会发生这种情况,不添加这段代码,真机模拟器都是好的[/quote] 加了的,只有高清图片[/quote] 这个设置过了 但是我随便找了一张低分辨率的图(443*273)模拟器和手机都可以了,还是不明白为什么会发生这种情况 郁闷了一下午了[/quote] 手动把navigationBar的translucent设为YES呢[/quote] 我试了一下,同样都是640*128的图片只是resolution不同一个是72pixels/inch一个是326 pixels/inch 72的就是好的 326的就出现问题[/quote] 有可能是图片本身的问题
LIUSIYU641 2014-11-03
  • 打赏
  • 举报
回复
引用 10 楼 zhangao0086 的回复:
[quote=引用 9 楼 LIUSIYU641 的回复:] [quote=引用 7 楼 LIUSIYU641 的回复:] [quote=引用 5 楼 LIUSIYU641 的回复:] [quote=引用 4 楼 zhangao0086 的回复:] 你用什么方式设置navigationBar的背景图的?
在appdelegate中使用 [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"title_bar_bg"] forBarMetrics:UIBarMetricsDefault]; 模拟器是7.0的真机是7.1的不知道为什么会发生这种情况,不添加这段代码,真机模拟器都是好的[/quote] 加了的,只有高清图片[/quote] 这个设置过了 但是我随便找了一张低分辨率的图(443*273)模拟器和手机都可以了,还是不明白为什么会发生这种情况 郁闷了一下午了[/quote] 手动把navigationBar的translucent设为YES呢[/quote] 我试了一下,同样都是640*128的图片只是resolution不同一个是72pixels/inch一个是326 pixels/inch 72的就是好的 326的就出现问题
LIUSIYU641 2014-11-03
  • 打赏
  • 举报
回复
引用 9 楼 LIUSIYU641 的回复:
[quote=引用 7 楼 LIUSIYU641 的回复:] [quote=引用 5 楼 LIUSIYU641 的回复:] [quote=引用 4 楼 zhangao0086 的回复:] 你用什么方式设置navigationBar的背景图的?
在appdelegate中使用 [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"title_bar_bg"] forBarMetrics:UIBarMetricsDefault]; 模拟器是7.0的真机是7.1的不知道为什么会发生这种情况,不添加这段代码,真机模拟器都是好的[/quote] 加了的,只有高清图片[/quote] 这个设置过了 但是我随便找了一张低分辨率的图(443*273)模拟器和手机都可以了,还是不明白为什么会发生这种情况 郁闷了一下午了[/quote] 还是不行,难道只有我一个人遇到这种情况吗
Bannings 2014-11-03
  • 打赏
  • 举报
回复
引用 9 楼 LIUSIYU641 的回复:
[quote=引用 7 楼 LIUSIYU641 的回复:] [quote=引用 5 楼 LIUSIYU641 的回复:] [quote=引用 4 楼 zhangao0086 的回复:] 你用什么方式设置navigationBar的背景图的?
在appdelegate中使用 [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"title_bar_bg"] forBarMetrics:UIBarMetricsDefault]; 模拟器是7.0的真机是7.1的不知道为什么会发生这种情况,不添加这段代码,真机模拟器都是好的[/quote] 加了的,只有高清图片[/quote] 这个设置过了 但是我随便找了一张低分辨率的图(443*273)模拟器和手机都可以了,还是不明白为什么会发生这种情况 郁闷了一下午了[/quote] 手动把navigationBar的translucent设为YES呢
加载更多回复(9)

29,028

社区成员

发帖
与我相关
我的任务
社区描述
主要讨论与iOS相关的软件和技术
社区管理员
  • iOS
  • 大熊猫侯佩
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧