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