【问题标题】:iOS: UIToolbar setBackgroundImage not workingiOS:UIToolbar setBackgroundImage 不工作
【发布时间】: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 工作得很好。

标签: ios uitoolbar


【解决方案1】:

根据文档,您需要使用 UIToolbar 的方法是

- setBackgroundImage:(UIImage *)backgroundImage forToolbarPosition:(UIToolbarPosition)topOrBottom barMetrics:(UIBarMetrics)barMetrics

你正在使用

- setBackgroundImage:(UIImage *)backgroundImage forBarMetrics:(UIBarMetrics)barMetrics

尝试使用它,看看它是否适合你。

More info here.

【讨论】:

    猜你喜欢
    • 2013-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-04
    • 2014-10-19
    • 2012-11-01
    • 2013-11-08
    • 1970-01-01
    相关资源
    最近更新 更多