子类UIButtons

时间:2013-10-15 09:15:01

标签: iphone ios css xcode uibutton

我在每个视图中有四个不同的UIViews和自定义UI按钮(10)。但是我想在每个视图中对其中的5个应用两个不同的背景颜色,即我需要应用each view 5 buttons -> redColor each view remaining 5 buttons->blue Color.

还有像CSS in which I can define two different global classes这样的东西,其中每个类都有必要应用于按钮的所有属性,并在创建按钮时声明该类名,以便button will inherit all the properties of that class? 我已经通过谷歌,但没有找到任何......

任何想法/帮助都将受到赞赏..

2 个答案:

答案 0 :(得分:2)

在Objective-C中没有CSS方法来定义按钮的属性,但是您可以创建UIButton的子类并创建2个主按钮,一个具有红色背景,另一个具有蓝色背景。

答案 1 :(得分:0)

UIAppearance API是Cocoa Touch中唯一的CSS等价物,所以如果您不想使用自定义子类,可以使用它:

[[UIButton appearanceWhenContainedIn:[ViewController class], nil] setBackgroundColor:[UIColor blueColor];