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

后端 未结 4 404
不知归路
不知归路 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:58

    Everything Jongsma said is right, you should use the initWithImage:style: message.

    The next problem is not the way you create the UIBarButtonItem, but the place you assign it. You create it with UIBarButtonItemStylePlain, which should normally render the icon's outline in white, but the rightBarButtonItem of a UINavigationItem (just like the left) is not allowed the UIBarButtonItemStylePlain. It's implicitly converted to UIBarButtonItemStyleBordered. In the bordered style the icon is rendered 'as is', which is black with a slight gradient.

    I think if you want the item in white on a bordered barButton, you'll have to touch the image itself.

提交回复
热议问题