Storyboard--UITabBarController 使用

利用storyboard新建UITabBarController時(shí),在設(shè)置好ImageSelected 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í)候需要更改一下UIImagewithRenderingMode屬性,通過查閱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è)置modeUIImageRenderingModeAlwaysOriginal
新建一個(gè)類,繼承 UITabBarController,更改StoryboardSceneclass即可

截屏2020-07-23 下午4.23.59.png

效果圖:


Jul-23-2020 16-30-06.gif
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容