iOS抽奖程序
#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
#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
- (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];
}
}
iOS抽奖程序的更多相关文章
- iOS 应用程序生命周期
开发应用程序都要了解其生命周期. 今天我们接触一下iOS应用程序的生命周期, iOS的入口在main.m文件: int main(int argc, char * argv[]) { @autorel ...
- [ios基础]IOS应用程序的生命周期问题
—程序的生命周期 a.程序的生命周期是指应用程序启动到应用程序结束整个阶段的全过程 b.每一个IOS应用程序都包含一个UIApplication对象,IOS系统通过该U ...
- iOS应用程序的生命周期
iOS应用程序一般都是由自己编写的代码和系统框架(system frameworks)组成,系统框架提供一些基本infrastructure给所有app来运行,而你提供自己编写的代码来定制app的外观 ...
- 使用jQuery+PHP+Mysql实现抽奖程序
抽奖程序在实际生活中广泛运用,由于应用场景不同抽奖的方式也是多种多样的.本文将采用实例讲解如何利用jQuery+PHP+Mysql实现类似电视中常见的一个简单的抽奖程序. 查看演示 本例中的抽奖程序要 ...
- iOS app 程序启动原理
iOS app 程序启动原理 Info.plist: 常见设置 建立一个工程后,会在Supporting files文件夹下看到一个"工程名-Info.plist"的文件, ...
- 发布iOS应用程序到苹果APP STORE完整流程
参考:http://blog.csdn.net/mad1989/article/details/8167529(xcode APP 打包以及提交apple审核详细流程(新版本更新提交审核)) http ...
- 从C#到Objective-C,循序渐进学习苹果开发(5)--利用XCode来进行IOS的程序开发
本随笔系列主要介绍从一个Windows平台从事C#开发到Mac平台苹果开发的一系列感想和体验历程,本系列文章是在起步阶段逐步积累的,希望带给大家更好,更真实的转换历程体验.前面几篇随笔主要介绍C#和O ...
- jQuery幸运大转盘_jQuery+PHP抽奖程序的简单实现
jQuery幸运大转盘_jQuery+PHP抽奖程序的简单实现 在线实例 查看演示 完整代码 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 ...
- 25个增强iOS应用程序性能的提示和技巧(高级篇)(2)
25个增强iOS应用程序性能的提示和技巧(高级篇)(2) 2013-04-16 14:56 破船之家 beyondvincent 字号:T | T 在开发iOS应用程序时,让程序具有良好的性能是非常关 ...
随机推荐
- Java获取.properties配置文件某一项value根据key值
public static String getProperty(String key){ InputStream in = PropertiesUtils.class.getResourceAsSt ...
- selenium2入门 用selenium安装、加载、启用插件(一)
一:下载 下载地址是:http://docs.seleniumhq.org/download/
- Ubuntu Ruby On Rails安装和配置
在这篇文章中ubuntu通过rvm安装ruby和rails.步借鉴了官方网站和网上信息,这里给大家分享. 1. 安装mapapis公钥: gpg --keyserver hkp://keys.gnup ...
- JS中childNodes深入学习
原文:JS中childNodes深入学习 <html xmlns="http://www.w3.org/1999/xhtml"> <head> <ti ...
- Session变量不能转移到下页.解决: session.use_trans_sid = 1
附:文摘 ============================================================ 在PHP使用SESSION的朋友可能会碰到这么一个问题.SESSIO ...
- 使用rem设计移动端自适应页面一(转载)
1.困扰多时的问题 在这之前做Web App开发的的时候,在自适应方面一般都是宽度通过百分比,高度以iPhone6跟iPhone5之间的一个平衡值写死,我们的设计稿都是iPhone5的640 * 11 ...
- C# 图片存入SQL Server数据库
OpenFileDialog openfiledialog1 = new OpenFileDialog(); if (openfiledialog1.ShowDialog() == DialogRes ...
- JavaScript中的execCommand()命令详解及实例展示
execCommand方法是执行一个对当前文档,当前选择或者给出范围的命令.处理Html数据时常用如下格式:document.execCommand(sCommand[,交互方式, 动态参数]) ,其 ...
- 配置Sublime Text 2 的Python运行环境
Sublime Text 2作为一款轻量级的编辑器,特点鲜明,方便使用,愈发受到普罗大众的喜爱,我个人最近也开始用了起来.同时,我近段时间还在学习Python的相关东西,所以开始用ST2来写Pytho ...
- 仿async/await(一)and Gulp:新一代前端构建利器
NET 4.5的async/await真是个神奇的东西,巧妙异常以致我不禁对其实现充满好奇,但一直难以窥探其门径.不意间读了此篇强文<Asynchronous Programming in C# ...