UIBarButtonItem icon white when added via IB, black when added programmatically

后端 未结 4 354
不知归路
不知归路 2020-12-30 12:59

When I add an icon to a UIBarButtonItem via the Interface Builder, the icon is displayed white. When I add the same icon file programmatically to another

4条回答
  •  生来不讨喜
    2020-12-30 13:45

    Answer: If you want it white, color your image white.

    Details:

    UIBarButtonItems behave a little differently depending on how you use them.

    When adding to a UIToolbar:

    initWithImage:style:target:action: creates "white icons" (image color is ignored, opaque pixels are used as a mask to create a white image).
    This is true for bordered and plain styles (but on UIToolbar only).

    initWithCustomView: displays normal colored image.

    When adding to a UINavigationItem:

    initWithImage:style:target:action: creates colored images and converts plain to bordered.

提交回复
热议问题