Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

set UIButton's buttonType programmatically [duplicate]

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?

like image 750
Jonathan. Avatar asked Sep 04 '25 17:09

Jonathan.


2 Answers

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

UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
like image 63
youshunei Avatar answered Sep 07 '25 16:09

youshunei


There's no way to change the .buttonType once it's set.

You can prepare two buttons, and hide one of them depending on the background color.

like image 43
kennytm Avatar answered Sep 07 '25 16:09

kennytm