【问题标题】:How to set Image in Tabbar not Tint color in ios?如何在 ios 中设置 Tabbar 中的图像而不是 Tint 颜色?
【发布时间】:2016-11-28 08:15:43
【问题描述】:

我有一个带有 UITabbar 的应用程序,我想在 Tabbar 中设置图像,但无法在 Tabbar 中设置图像。而不是像图像一样,我得到了色调颜色的图像形状,是否可以像在 Tabbar 中一样设置图像? .

我已尝试此代码,但无法设置图像。

UITabBar *tabBar = self.tabBar;

UITabBarItem *targetTabBarItem = [[tabbar items] objectAtIndex:0]; // whichever tab-item
UIImage *selectedIcon = [UIImage imageNamed:@"name-of-selected-image.png"];
[targetTabBarItem setSelectedImage:selectedIcon];

【问题讨论】:

  • 通过属性检查器添加图片

标签: ios objective-c uitabbarcontroller uistoryboard uitabbar


【解决方案1】:

选择您的 TabBar 项目并像这样设置您的图像

设置选定的色调试试这个

[[UITabBar appearance] setTintColor:[UIColor whiteColor]];

    [UITabBarItem.appearance setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]} forState:UIControlStateNormal];
    [[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:@"name-of-selected-image.png"]];
    [[UITabBar appearance]setSelectedItem:[[UITabBar appearance].items objectAtIndex:2]];

【讨论】:

    【解决方案2】:

    您需要将图像属性属性Render As 设置为Original Image。要更改此设置,请从资产中选择您的图像,然后在 Attributes Inspector 中将 Render As 属性设置为 Original Image,如下所示。

    【讨论】:

    • 但是图像色调颜色没有变化?
    • @kishor0011 是的,在将 rander 模式设置为原始图像后,您不能对该图像使用色调颜色。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-06
    • 2016-12-20
    • 2016-10-30
    • 1970-01-01
    相关资源
    最近更新 更多