0

我在每个视图中有四个不同的 UIViews 和自定义 UIbuttons(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? 我通过谷歌但没有找到任何...

任何想法/帮助将不胜感激..

4

2 回答 2

2

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

于 2013-10-15T09:18:00.663 回答
0

UIAppearanceAPI 是 Cocoa Touch 中唯一等效于 CSS 的,因此如果您不想使用自定义子类,可以使用它:

[[UIButton appearanceWhenContainedIn:[ViewController class], nil] setBackgroundColor:[UIColor blueColor];
于 2013-10-15T09:22:00.717 回答