Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何以编程方式将自定义图像设置为和UIBarButtonim_Ios_Swift_Xcode_Uiimage_Uibarbuttonitem - Fatal编程技术网

Ios 如何以编程方式将自定义图像设置为和UIBarButtonim

Ios 如何以编程方式将自定义图像设置为和UIBarButtonim,ios,swift,xcode,uiimage,uibarbuttonitem,Ios,Swift,Xcode,Uiimage,Uibarbuttonitem,我在为UIBarButtonItem指定自定义图像时遇到问题,主要问题是创建按钮时图像显示为白色正方形。 这是我的密码: fileprivate func configureNavigationBar() { tabBarController?.navigationItem.title = lot.name let exportImg: UIImage = UIImage(named: "action.png")! let addButton =

我在为UIBarButtonItem指定自定义图像时遇到问题,主要问题是创建按钮时图像显示为白色正方形。 这是我的密码:

fileprivate func configureNavigationBar() {
        tabBarController?.navigationItem.title = lot.name
        let exportImg: UIImage = UIImage(named: "action.png")!
        let addButton = UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(showCreationView(_:)))
        let exportByEmail = UIBarButtonItem(image: exportImg, style: .done, target: self, action: #selector(exportDataByEmail(_:)))
        tabBarController?.navigationItem.rightBarButtonItems = [exportByEmail,addButton]
    }
问题在于exportByEmail,图像位于从我的资产添加的变量exportImg中:

从我的代码中获得的结果:

您的图像背景必须是透明的,并且您可以将“始终原始渲染模式”设置为“图像”,以便在不进行更改的情况下显示,如下所示

let exportByEmail = UIBarButtonItem(image: exportImg.withRenderingMode(.alwaysOriginal), style: .done, target: self, action: #selector(exportDataByEmail(_:)))