【问题标题】:UIBarButtonItem: how to skin the highlighted stateUIBarButtonItem:如何为突出显示的状态设置皮肤
【发布时间】:2014-03-06 02:53:46
【问题描述】:

我有一个 UIBarButtonItem 的图像,但我不想显示突出显示的状态。现在,当按下按钮时,我的图像变灰了。我尝试为突出显示的状态设置相同的图像,但没有做任何事情。

谢谢

【问题讨论】:

    标签: ios uibarbuttonitem


    【解决方案1】:

    我的朋友试试这个:

    https://developer.apple.com/library/ios/DOCUMENTATION/UIKit/Reference/UIButton_Class/UIButton/UIButton.html#//apple_ref/occ/instp/UIButton/adjustsImageWhenHighlighted

    设置按钮

    adjustImageWhenHighlighted = NO;
    

    应该可以解决问题。

    希望对您有所帮助。干杯

    更新:

    // Initialize the UIButton
    UIButton *customButton= [UIButton buttonWithType:UIButtonTypeCustom];
    
    //normal_button.png and selected_button.png need to be created by you
    [customButton setBackgroundImage: [UIImage imageNamed:@"normal_button.png"] forState:UIControlStateNormal];
    [customButton setBackgroundImage: [UIImage imageNamed:@"normal_button.png"] forState:UIControlStateSelected];
    
    UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithCustomView: customButton];
    

    另一种方法。

    【讨论】:

    • 谢谢,但这仅适用于 UIBUtton 类,不适用于 UIBarButtonItem
    • 很高兴为您提供帮助。对不起,我第一次没有更具体。编码愉快。
    • 我试过了,没用。我的自定义按钮图像不会显示。
    • 如果您在问题中显示一些代码和屏幕截图,我可能会更好地帮助您。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-22
    相关资源
    最近更新 更多