zoukankan      html  css  js  c++  java
  • iOS抽奖程序

    iOS抽奖程序



    代码下载地址: http://vdisk.weibo.com/s/HKehU




    我们要先写一个数据模型:Model.h
    #import <Foundation/Foundation.h>
    
    @interface Model : NSObject
    @property (strong,nonatomic) NSArray* ClassArray;
    
    @end

    Model.m代码如下:
    #import "Model.h"
    
    @implementation Model
    @synthesize ClassArray = _ClassArray;
    -(id)init
    {
        if (self = [super init]) {
            self.ClassArray = [[NSArray alloc] initWithObjects:@"ddd",@"aaa",@"vvv",@"fff",nil];
        }
        return self;
    }
    @end


    ViewController.h

    #import <UIKit/UIKit.h>
    #import "Model.h"
    @interface ViewController : UIViewController
    
    @property (strong,nonatomic) UILabel* LuckyLabel;
    @property (strong,nonatomic) Model* myModel;
    @property (strong,nonatomic) NSTimer* TimeController;
    @property (strong,nonatomic) UIButton* TimeButton;
    @property (assign,nonatomic) BOOL TimeBool;
    -(void)StopTime;
    -(void)addLabel;
    -(void)addModel;
    -(void)addTime;
    -(void)addButton;
    @end




    ViewController.m

    - (void)viewDidLoad
    {
        [super viewDidLoad];
    	// Do any additional setup after loading the view, typically from a nib.
        TimeBool = YES;
     
        UIImageView* backImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"002.png"]];
        
        backImageView.frame = CGRectMake(0, 0, 768, 1024);
        [self.view addSubview:backImageView];
        [self addLabel];
       
        [self addButton];
      
        
    }


    添加标签
    -(void)addLabel
    {
        self.LuckyLabel = [[UILabel alloc] initWithFrame:CGRectMake(300, 200, 260, 200)];
        [self.LuckyLabel setFont:[UIFont fontWithName:@"Verdana" size:63]];
        self.LuckyLabel.backgroundColor = [UIColor clearColor];
        self.LuckyLabel.textAlignment= UITextAlignmentCenter;
        [self.view addSubview:self.LuckyLabel];
        UILabel* Title = [[UILabel alloc] initWithFrame:CGRectMake(200, 20, 350, 200)];
        Title.backgroundColor = [UIColor clearColor];
        Title.textAlignment = UITextAlignmentCenter;
        [Title setFont:[UIFont fontWithName:@"Verdana" size:30]];
        Title.text = @"幸运大抽奖";
        [self.view addSubview:Title];
        UILabel* NameLabel = [[UILabel alloc] initWithFrame:CGRectMake(40, 200, 260, 200)];
        NameLabel.textAlignment = UITextAlignmentCenter;
        [NameLabel setFont:[UIFont fontWithName:@"Verdana" size:50]];
        NameLabel.backgroundColor = [UIColor clearColor];
        
        NameLabel.text = @"幸运学生:";
        [self.view addSubview:NameLabel];
    
    
    
    }


    添加模型数据
    -(void)addModel
    { 
        if (m_pInt ==self.myModel.ClassArray.count) {
            m_pInt = 0;
        }
       
        self.LuckyLabel.text = [self.myModel.ClassArray objectAtIndex:m_pInt];
        m_pInt++;
        
       
    }

    添加定时器
    -(void)addTime
    {
        self.TimeController = [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(addModel) userInfo:nil repeats:YES];
    }


    添加按钮
    -(void)addButton
    {
        self.myModel = [[Model alloc] init];
        self.TimeButton = [UIButton buttonWithType:UIButtonTypeCustom];
        self.TimeButton.frame = CGRectMake(266, 800, 200, 100);
        [self.TimeButton setTitle:@"开始抽奖" forState:UIControlStateNormal];
        self.TimeButton.titleLabel.textAlignment = UITextAlignmentCenter;
        [self.TimeButton.titleLabel setFont:[UIFont fontWithName:@"Verdana" size:35]];
        [self.TimeButton addTarget:self action:@selector(StopTime) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:self.TimeButton];
    }

    暂停方法
    -(void)StopTime
    {
        if (TimeBool) {
            [self addTime];
            TimeBool = NO;
            [self.TimeButton setTitle:@"停止" forState:UIControlStateNormal];
         
    
        }
        else{
            //Time停止
            [self.TimeController invalidate];
            TimeBool = YES;
            [self.TimeButton setTitle:@"开始抽奖" forState:UIControlStateNormal];
        }
    }


  • 相关阅读:
    全--教程API, gem 'rest-client'(用于发简单请求); 请求测试;
    GoRails教程自建Rails 的 API; gem 'jbuilder'简单用法;使用JWT进行验证(git上的实做);curl命令使用;status状态码;JWT文档翻译摘录;
    go Rails 知识点,Concepts Series:url和parameter; 建立Rails App Templates;报错页面debug; counter_cache
    FontAwesome::Sass(5.x版)使用帮助。
    问题记录:
    slim(4621✨)
    物联网平台开发及应用:基于CC2530和ZigBee
    CATIA V5-6 R2017基础、进阶、高手一本通
    计算机组装与维护标准教程(2015—2018版)
    Web程序设计——ASP.NET(第2版)
  • 原文地址:https://www.cnblogs.com/jiangu66/p/3162820.html
Copyright © 2011-2022 走看看