我自己的关灯游戏代码

本文介绍了如何使用UIButton+Create分类创建关灯游戏,通过视图控制器创建游戏界面,设置背景图片和按钮,并实现点击按钮时改变状态的逻辑,包括过关条件检查和步数记录。
摘要由CSDN通过智能技术生成

//用到的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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值