ios - 删除突出显示栏按钮上的白色

标签 ios objective-c

在我的一个 Controller 中,我有如下的条形按钮图像(点击时): enter image description here

在我的另一个 Controller 中它看起来像:

enter image description here

它总是使用 Assets 中的相同图像。我需要我的按钮始终是第二个变体。

第一个(错误的)按钮声明如下:

bbiRight = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:riVM.itemPictureName] style:UIBarButtonItemStylePlain target:nil action:nil];

                [RACObserve(((id<CDRRightNavItemProtocol>)self.viewModel), itemPictureName) subscribeNext:^(NSString * x) {
                    [bbiRight setImage:[UIImage imageNamed:x]];
                }];

第二个(正确的)是:

 UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setImage: [UIImage imageNamed: @"m_starnotactive"] forState:UIControlStateNormal];
    [btn setImage: [UIImage imageNamed: @"m_staractive"] forState:UIControlStateSelected];
    btn.frame = (CGRect){88,11, 22,22};
    btn.rac_command = self.viewModel.cmdSaveToFavorites;
    RAC(btn, selected) = RACObserve(self.viewModel, inFavorites);

    UIBarButtonItem *bbiFav = [[UIBarButtonItem alloc] initWithCustomView:btn];
    self.navigationItem.rightBarButtonItem = bbiFav;

问题是,第一种情况在我的应用程序中的许多类中使用的抽象类中使用,如何修改它以便我的栏按钮在选择时不会看起来是白色的?

最佳答案

您可能想尝试将 setTitleColor:forState:UIControlStateHighlightedUIControlStateSelected 结合使用,以指定选择按钮时的颜色。

如果您的图像 Assets 是透明的,您可能还想尝试使用 imageWithRenderingMode: 使用 UIImageRenderingModeAlwaysTemplate 并根据您的要求使用 tintColor 配置颜色。

关于ios - 删除突出显示栏按钮上的白色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37103698/

相关文章:

c++ - 预期的说明符限定符列表之前... C++/Objective-C iPhone 项目中的错误

ios - 在 Swift 项目中使用以 Objective-c 编写的库类

ios - 共享大块数据 iOS

ios - 在 iPad 的同一 View 中加载多个 popOver

ios - UIScrollView 改变边界

ios - 如何将数据传递到实例化 Storyboard 中 UINavigationController 的 rootViewController?

objective-c - 检测 NSOpenGLView 上的触摸

ios - 如何获取在 iOS 应用中观看视频的时长

ios - 检测点击 CCTableView 单元格

ios - iOS 应用程序上的多个通知