我正在使用swift制作一个IOS应用程序。我的应用程序中有一个UIToolBar
,我需要更改它的背景。我在 Objective-C 中使用以下代码来做到这一点:
[topBar setBackgroundImage:[UIImage imageNamed:@"header_bg.png"] forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault];
现在,当我用 swift 重写代码时,它看起来像这样:
topBar.setBackgroundImage(UIImage(named:"header_bg.png"), forToolbarPosition: UIToolbarPositionAny, barMetrics: UIBarMetricsDefault)
这显示了Use of unresolved type UIBarMetricsDefault
和的错误Use of unresolved type UIToolbarPositionAny
。所以我进行了搜索并找到了这个文档。根据文档,我更改了这样的代码:
topBar.setBackgroundImage(UIImage(named:"header_bg.png"), forToolbarPosition: Any, barMetrics: Default)
但它仍然显示相同的错误。有人知道这里有什么问题吗?