set UIButton's buttonType programmatically [duplicate]

廉价感情. 提交于 2019-12-22 01:24:19

问题


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?


回答1:


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.




回答2:


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

UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];


来源:https://stackoverflow.com/questions/3080011/set-uibuttons-buttontype-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!