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(_:)))
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加