set UIButton's buttonType programmatically

Jonathan. picture Jonathan. · Jun 20, 2010 · Viewed 42.6k times · Source

I have a UIButton which I've added in IB, however the view behind this button changes color and I need to switch the button's type between InfoDark and InfoLight. Bizarrely though, buttonType property is read only. So how can i switch between light and dark info buttons?

Answer

youshunei picture youshunei · Sep 5, 2011

You can't set buttonType readonly property, use below may help:

UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];