How to set image for bar button with swift?

前端 未结 14 1204
一个人的身影
一个人的身影 2020-11-28 04:22

I am trying to set an Image for bar button Item for that I have an image like:

\"enter

14条回答
  •  醉酒成梦
    2020-11-28 05:17

    If you have set up your UIBarButtonItem with an image in the storyboard, one small hack to change the renderingMode is to add the following code to your viewDidLoad(). This way you don't have to resort to adding the entire button and image in code.

    if let navButton = self.navigationItem.leftBarButtonItem, let buttonImage = navButton.image {
        navButton.image = buttonImage.withRenderingMode(.alwaysOriginal)
    }
    

提交回复
热议问题