我已經使用自定義UIButton初始化UIBarButtonItem,並將其設置爲導航控制器中的rightBarButtonItem。UIBarButtonItem:在動畫過程中更改標題字體顏色
UIBarButtonItem *rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightNavigationButton];//rightNavigationButton is the custom UIButton I set up before
self.navigationItem.rightBarButtonItem = rightBarButtonItem;
通過UIButton的外觀代理,我設置了UIControlStates(Normal/Disabled/Highlighted)的顏色。 UIBarButtonItem的行爲如預期。
當按下「保存按鈕」時,我想突出顯示UIBarButtonItem,以提供已保存內容的視覺反饋。 我想要做的是通過在保存動畫期間改變標題的顏色來模擬UIBarButtonItem的突出顯示,因爲它似乎不能以編程方式觸發突出顯示動畫(或設置選定的屬性)(also mentioned in this post)
所以我所做的就是設置一個IBOutlet屬性,將它連接到InterfaceBuilder中的UIBarButtonItem併爲其分配rightBarButtonItem。當按下「保存按鈕」時,我試着這樣:
[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
];
但是根本沒有什麼事情發生。我以某種方式工作的唯一方法是禁用/啓用它。但由於着色禁用和突出顯示應該是不同的,我需要這兩種狀態,這不是一個真正的選擇。
任何幫助表示讚賞!
檢查是否可以將動畫塊中標題的字母顏色從0改爲1。 – sridevi 2013-05-02 16:36:43
是的,我可以改變alpha通道。 (Reinhard也指出這個道具是可以動畫的)但是這並不能真正幫助我改變顏色的問題。我錯過了什麼嗎? – codingPanda 2013-05-03 09:31:38