在 Swift 中自定义栏按钮项目

Customize Bar button Item in Swift

我对编码非常陌生,我一直在观看大量关于如何自定义(添加我自己的图像)工具栏上的栏按钮项目的 YouTube 视频,并且 none 的方式似乎是正在工作。

有人能帮我指出正确的方向吗?

或者我应该只创建一个按钮并添加图像和 "command" 吗?

谢谢!

Screenshot of the problem

如何将图像添加到 UIBarButtonItem

// Create toolbar
let toolbar = UIToolbar()
toolbar.sizeToFit()

// My button with an image
let button = UIBarButtonItem(image: UIImage(named: "myImageName"), style: .done, target: self, action: nil) // Add a selector if you want an action when it is clicked

// Create toolbar using items
toolbar.items = [button]