繁体   English   中英

iOS-标签栏项目图像修改

[英]IOS - tab bar item image modifications

我想将选项卡栏项目图像的默认颜色更改为图像的原始颜色(黑色),而不是未选择时的灰色。

选择后,我还想将选项卡栏项目图像更改为填充版本。

最后一件事是位置。.似乎期望文本在其下而不会居中,如何垂直居中并可能缩小它?

我目前以这种方式设置它:

   let profileNavController = UINavigationController(rootViewController: profileController)
        profileNavController.tabBarItem.image = UIImage(named: "icon_tab_user")

这是选择和未选择的样子: 在此处输入图片说明 在此处输入图片说明

从苹果我们知道

默认情况下,实际的未选择和选择的图像是根据源图像中的alpha值自动创建的。 为防止系统变色,请为图像提供UIImageRenderingModeAlwaysOriginal。

在这里看看。
更改标签栏项目图像和文本颜色iOS

我可以使用以下方法更改突出显示和不突出显示的图像以及位置:

let profileNavController = UINavigationController(rootViewController: profileController)
        let profileTabBarItem  = UITabBarItem(title: nil, image: UIImage(named: "icon_tab_user")?.withRenderingMode(UIImageRenderingMode.alwaysOriginal), selectedImage: UIImage(named: "icon_tab_user_highlighted"))
        profileTabBarItem.imageInsets = UIEdgeInsetsMake(5.5, 0, -5.5, 0)
        profileNavController.tabBarItem = profileTabBarItem

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM