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

显示效果:

可以发现,图片的边框是加载出来了,不过没有正常
渲染
主要是因为storyboard
默认渲染了设置的图片,在设置普通的Image时候不会出现问题,不过在Tab bar Item
的时候需要更改一下UIImage
的withRenderingMode
属性,通过查阅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
}
我们需要把设置mode
为UIImageRenderingModeAlwaysOriginal
新建一个类,继承 UITabBarController
,更改Storyboard
里 Scene
的class
即可

效果图:

网友评论