简体   繁体   English

子类UIButtons

[英]Subclass UIButtons

I have four different UIViews with custom UIbuttons(10) in each view.But I want to apply two different backgroundcolors to 5 of them in each view ie I need to apply each view 5 buttons -> redColor each view remaining 5 buttons->blue Color. 我在每个视图中有四个不同的UIViews和自定义UI按钮(10)。但我想在每个视图中应用两个不同的backgroundcolors到5个,即我需要应用each view 5 buttons -> redColor each view remaining 5 buttons->blue Color. each view 5 buttons -> redColor each view remaining 5 buttons->blue Color.

So is there any thing like CSS in which I can define two different global classes in which each class will have all the properties necessary to be applied to button , and declaring that class name while creating button so that the button will inherit all the properties of that class? 那么有没有像CSS in which I can define two different global classes ,其中每个类都具有应用于按钮所需的所有属性,并在创建按钮时声明该类名,以便button will inherit all the properties of that class? I have gone through Google but didnot find any ... 我已经通过谷歌,但没有找到任何...

Any idea /help would be appreciated.. 任何想法/帮助将不胜感激..

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

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM