//用到的UIButton+Create分类
#import "UIButton+Create.h"
@implementation UIButton (Create)
+ (UIButton *)buttonWithType:(UIButtonType)type frame:(CGRect)frame title:(NSString *)title target:(id)target action:(SEL)action backgroundColor:(UIColor *)backgroundColor alpha:(CGFloat)alpha
{
UIButton *button = [UIButton buttonWithType:type];
button.frame = frame;
[button setTitle:title forState:UIControlStateNormal];
[button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
button.backgroundColor=backgroundColor;
button.alpha=alpha;
button.layer.cornerRadius=10;
return button;
}
@end
//在视图控制器创建TheFirstPass类一个的对象
- (void)viewDidLoad
{
[super viewDidLoad];
TheFirstPass *aview=[[TheFirstPass alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];
aview.tag=100;
[self.view addSubview:aview];
[aview release];
// Do any additional setup after loading the view.
}
//实现
#import "TheFirstPass.h"
#import "UIButton+Create.h"
@implementation TheFirstPass
- (id)initWithFrame:(CGRect)frame
{
//非ARC模式
self = [super initWithFrame:frame];
if (self) {
//添加背景视图
UIImageView *img=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"12.jpg"]];
img.frame=CGRectMake(0, 0, 320, 480);
img.userInteractionEnabled=YES;
[self addSubview:img];
[img release];
//用分类创建button
for (int i=0; i<5; i++) {
for (int j=0; j<5; j++) {
UIButton *button=[UIButt