【问题标题】:Adding System Image to navigation bar programmatically以编程方式将系统图像添加到导航栏
【发布时间】:2019-11-16 19:54:15
【问题描述】:

我正在尝试从情节提要转向以编程方式进行编码。我正在尝试将 barbuttonitem 添加到我的导航栏。但是,我不想使用自己的图像,我想使用默认的系统图像,例如“magnifyingglass.circle”。

这是我的代码:

let button = UIBarButtonItem.init(image: UIImage(contentsOfFile: "magnifyingglass.circle") , style: .plain, target: nil, action: nil)
navigationItem.leftBarButtonItem = button

但是,我的导航栏没有添加任何内容。

【问题讨论】:

    标签: ios swift uiimage uibarbuttonitem navigationbar


    【解决方案1】:

    您使用了错误的 UIImage 初始化程序。您尝试使用的那个需要图像文件的完整路径。你想要UIImage(systemName:)

    let button = UIBarButtonItem(image: UIImage(systemName: "magnifyingglass.circle") , style: .plain, target: nil, action: nil)
    

    【讨论】:

      猜你喜欢
      • 2011-02-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-05
      相关资源
      最近更新 更多