ios - iOS:UIToolbar setBackgroundImage无法正常工作

标签 ios uitoolbar

我无法更改uitoolbar背景图片。给出错误。

此NavigationBar代码正在工作。

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];

最佳答案

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

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

您正在使用
- setBackgroundImage:(UIImage *)backgroundImage forBarMetrics:(UIBarMetrics)barMetrics

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

More info here

关于ios - iOS:UIToolbar setBackgroundImage无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16175331/

相关文章:

ios - 如何通过 list 调试 Apple Enterprise Deployment?

ios - 从 Mobile Safari (iOS8) 访问 iPhone 相机

具有不同大小的 ios uisegmentedcontrol

iphone - UIToolBar 的 View 转换动画不正确

ios - 自动布局 iOS 11 工具栏 UIBarButtonItem 与 customView

ios - Ansible regex_findall 多个字符串

iOS swift UICollectionView 在滚动超过第一个屏幕后失去单元格约束

ios - UNNotification 的重复间隔

iOS - 使工具栏滚动到底部

objective-c - 调整 UIToolbar 的大小以适合其项目?