【发布时间】:2013-04-23 17:16:15
【问题描述】:
我无法更改 uitoolbar 背景图像。给出错误。
此导航条码正在工作。
UIImage *navBackgroundImage = [UIImage imageNamed:@"bartop.png"];
[[UINavigationBar appearance] setBackgroundImage:navBackgroundImage forBarMetrics:UIBarMetricsDefault];
但是这个工具栏代码不起作用并给出错误。
UIImage *navBackgroundImage = [UIImage imageNamed:@"bartop.png"];
[[UIToolbar appearance] setBackgroundImage:navBackgroundImage forBarMetrics:UIBarMetricsDefault];
我哪里错了?
更新:
此代码正在运行:
UIImage *testimage = [[UIImage imageNamed:@"bartop"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
[[UIToolbar appearance] setBackgroundImage:testimage forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault];
[[UIToolbar appearance] setBackgroundImage:testimage forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsLandscapePhone];
【问题讨论】:
-
你不应该添加图片扩展名.png,因为它会被忽略2x。
-
它不起作用,我仍然收到错误。
-
这不是答案,这只是一个信息:p
-
哦,那非常感谢。 :D
-
@AnoopVaidya 我总是使用带有
UIImage的扩展名,而@2x 工作得很好。