以编程方式设置UIButton的buttonType

Jon*_*an. 23 iphone objective-c uibutton programmatically-created

我有一个UIButton我在IB中添加的,但是这个按钮后面的视图会改变颜色,我需要在InfoDarkInfoLight之间切换按钮的类型.但奇怪的是,buttonType财产是只读的.那么如何在明暗信息按钮之间切换?

you*_*nei 53

你不能设置buttonType readonly属性,使用下面可能有帮助:

UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
Run Code Online (Sandbox Code Playgroud)

  • 什么时候覆盖UIButton类?(我的意思是子类) (11认同)

ken*_*ytm 26

没有办法改变.buttonType它的设置.

您可以准备两个按钮,并根据背景颜色隐藏其中一个按钮.