Set custom images to the UIBarButtonItem but it doesn't show any image

后端 未结 2 790
无人共我
无人共我 2020-12-02 02:27

I want to set custom images to the UIBarButtonItem but it only shows a rectangular box around and It doesn\'t show the actual image.

func setupBrowserToolbar         


        
相关标签:
2条回答
  • 2020-12-02 03:05

    Swift 3 , 4 update

    From swift 3, the method is changed to the following format

    UIImage(named:"yourImageName")!.withRenderingMode(.alwaysOriginal)
    
    0 讨论(0)
  • 2020-12-02 03:06

    Thats because UIBarButtonItem image's default rendering mode always draw the image as a template image, ignoring its color information (UIImageRenderingModeAlwaysTemplate). Just create your image using UIImage's method imageWithRenderingMode always original.

    UIImage(named: "yourImageName")!.withRenderingMode(.alwaysOriginal)
    
    0 讨论(0)
提交回复
热议问题