Storyboard--UITabBarController 使用

利用storyboard新建UITabBarController时,在设置好ImageSelected Image之后,图片不能正常显示,选中时为蓝色,未选中时为灰色,没有正确显示图片样式。
Storyboard设置:

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

显示效果:

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

可以发现,图片的边框是加载出来了,不过没有正常渲染

主要是因为storyboard默认渲染了设置的图片,在设置普通的Image时候不会出现问题,不过在Tab bar Item的时候需要更改一下UIImagewithRenderingMode属性,通过查阅API文档,可以看到有以下几种设置方式

/* 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
    }

我们需要把设置modeUIImageRenderingModeAlwaysOriginal
新建一个类,继承 UITabBarController,更改StoryboardSceneclass即可

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

效果图:


Jul-23-2020 16-30-06.gif
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。