利用storyboard新建UITabBarController時(shí),在設(shè)置好Image和Selected Image之后,圖片不能正常顯示,選中時(shí)為藍(lán)色,未選中時(shí)為灰色,沒有正確顯示圖片樣式。
Storyboard設(shè)置:

截屏2020-07-23 下午4.07.32.png
顯示效果:

Jul-23-2020 16-06-02.gif
可以發(fā)現(xiàn),圖片的邊框是加載出來了,不過沒有正常
渲染
主要是因?yàn)?code>storyboard默認(rèn)渲染了設(shè)置的圖片,在設(shè)置普通的Image時(shí)候不會(huì)出現(xiàn)問題,不過在Tab bar Item的時(shí)候需要更改一下UIImage的withRenderingMode屬性,通過查閱API文檔,可以看到有以下幾種設(shè)置方式
/* Images are created with UIImageRenderingModeAutomatic by default.
An image with this mode is interpreted as a template image or an original image based on the context in which it is rendered.
For example, navigation bars, tab bars, toolbars, and segmented controls automatically treat their foreground images as templates, while image views and web views treat their images as originals.
You can use UIImageRenderingModeAlwaysTemplate to force your image to always be rendered as a template or UIImageRenderingModeAlwaysOriginal to force your image to always be rendered as an original.
*/
@available(iOS 7.0, *)
public enum RenderingMode : Int {
case automatic = 0 // Use the default rendering mode for the context where the image is used
case alwaysOriginal = 1 // Always draw the original image, without treating it as a template
case alwaysTemplate = 2 // Always draw the image as a template image, ignoring its color information
}
我們需要把設(shè)置mode為UIImageRenderingModeAlwaysOriginal
新建一個(gè)類,繼承 UITabBarController,更改Storyboard里 Scene的class即可

截屏2020-07-23 下午4.23.59.png
效果圖:

Jul-23-2020 16-30-06.gif