Making uibarbuttonitems fade
Asked Answered
C

3

10

I have a navigation bar that is set up and controlled completely with code. So it does not show up in IB. I have a button appear by "self.navigationitem.rightbarbutton = myButton;" An I make it go away by setting it equal to NIL. What I am wondering is how could I make it fade in and out?

Cornett answered 10/8, 2011 at 2:55 Comment(0)
C
23

I found what worked best for me

[self.navigationItem setRightBarButtonItem:myButton animated:YES];

And then

[self.navigationItem setRightBarButtonItem:nil animated:YES];

To make it fade out.

Cornett answered 7/6, 2012 at 20:51 Comment(0)
V
2

Swift version

fade in: navigationItem.setRightBarButtonItem(myButton, animated: true)

fade out: navigationItem.setRightBarButtonItem(nil, animated: true)

Verso answered 20/12, 2016 at 8:22 Comment(0)
F
0

Unfortunately there is no built in way to animate this for bar button items in a navigation bar. UIBarButtonItem is not a view or a control so it does not have animatable properties like alpha.

For bar button items in a UIToolbar, there is a way to animate. See this answer for details:

Is it possible to use Core Animation to fade out a UIBarButtonItem?

Fleenor answered 2/2, 2012 at 15:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.