setting image for UIBarButtonItem - image stretched

前端 未结 6 1893
北荒
北荒 2020-12-03 13:31

When I try to use UIBarButtonItem\'s \"initWithImage\" to initialize a navigation bar custom image, it comes out washed-up and stretched against a black navigation bar. This

6条回答
  •  不知归路
    2020-12-03 13:58

    The displayed images on bar button items are 'derived' from the source image (it uses only the alpha channel values in rendering but that all looks ok in your image). Its possibly just not the right size - you might need to open the image file and crop it to the right size.

    You could also try looking at whether setting the imageInsets property (inherited by UIBarButtonItem from UIBarItem) can be used to adjust the size in a way to stop it getting stretched.

    Doco on the bar item images says the following:

    The images displayed on the bar are derived from this image. If this image is too large to fit on the bar, it is scaled to fit. Typically, the size of a toolbar and navigation bar image is 20 x 20 points.

提交回复
热议问题