【问题标题】:Customize Bar button Item in Swift在 Swift 中自定义栏按钮项
【发布时间】:2023-03-30 15:18:01
【问题描述】:

我对编码非常陌生,我一直在观看大量关于如何自定义(添加我自己的图像)到工具栏上的栏按钮项的 YouTube 视频,但似乎没有一种方法有效。

有人可以帮助或指出正确的方向吗?

或者我应该只创建一个按钮并将图像和“命令”添加到其中?

谢谢!

Screenshot of the problem

【问题讨论】:

  • 您能更具体地说明您想要什么吗?您是在尝试链接条形按钮项目以执行某项操作,还是在安排/移动它们时遇到问题?
  • l你说的customize是什么意思?请更具体。
  • 我所说的自定义是在工具栏上用我自己的图像添加/替换栏按钮项。

标签: ios swift uibarbuttonitem uitoolbar


【解决方案1】:

如何将图像添加到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]

【讨论】:

  • 成功!!非常感谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-02-14
  • 1970-01-01
相关资源
最近更新 更多