h_h
h_h

Reputation: 1231

hide and show a ui nav bar button

I am having a situation in which I have to hide the button on the right side of nav bar. Button name is btnRefresh, and I can hide it successfully by this way

self.nvbar.topItem?.rightBarButtonItem = nil

but when I use this for showing it again, it didn't get displayed again

self.nvbar.topItem?.rightBarButtonItem = btnRefresh

Any help???

Upvotes: 0

Views: 315

Answers (1)

AaoIi
AaoIi

Reputation: 8396

You need to change the tint color to clear and disable the button as the following :

let barButtonItem = UIBarButtonItem()
barButtonItem.tintColor = .clear
barButtonItem.isEnabled = false

And to display it again change the color and enable it again :

barButtonItem.tintColor = .black 
barButtonItem.isEnabled = true

Upvotes: 1

Related Questions