I've initialized a UIBarButtonItem with a custom UIButton and set it to be the rightBarButtonItem within a navigation controller.
UIBarButtonItem *rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightNavigationButton];//rightNavigationButton is the custom UIButton I set up before
self.navigationItem.rightBarButtonItem = rightBarButtonItem;
Via the appearance proxy of UIButton I set up the colours for the UIControlStates (Normal/Disabled/Highlighted). The UIBarButtonItem is behaving as expected.
When a "save-button" is pressed, I want to highlight the UIBarButtonItem to give a visual feedback that something has been saved. What I'm trying to do is to simulate highlighting of the UIBarButtonItem through just changing the color of the title during the saving animation since it doesn't seem that can trigger the highlighting animation (or set a selected property) programmatically (also mentioned in this post)
So what I did is set a IBOutlet property, hooked it up to the UIBarButtonItem in InterfaceBuilder and assigned the rightBarButtonItem to it. When the "save-button" is pressed I'm trying this:
[UIView animateWithDuration:0.5f
delay:0.0f
options:UIViewAnimationCurveEaseOut
animations:^{
//some other animation code here
[self.barButtonItemOutlet setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIFont fontWithName:FONT_ICON size:FONTSIZE],UITextAttributeFont,
HIGHLIGHT_COLOUR,UITextAttributeTextColor,
[NSValue valueWithUIOffset:UIOffsetMake(0, 0)],UITextAttributeTextShadowOffset,
[UIColor colorWithRed:0 green:0 blue:0 alpha:0.0],UITextAttributeTextShadowColor,nil]
forState:UIControlStateNormal];
}
completion:nil
];
But there is nothing happening at all. The only way I got it to somehow work was to disable/enable it. But since colouring for disabling and highlighting should be different and I need both of these states this is not really an option.
Any help is appreciated!