iOS 摇号

作者: GF极客天涯 | 来源:发表于2017-05-13 14:33 被阅读58次

代码不多就不提供demo了,直接贴代码,供娱乐!

摇号.gif
//
//  ViewController.m
//  摇号
//
//  Created by 纪高飞 on 17/5/13.
//  Copyright © 2017年 纪高飞. All rights reserved.
//

#import "ViewController.h"
#define  kScreenW   [UIScreen mainScreen].bounds.size.width
#define  kScreenH   [UIScreen mainScreen].bounds.size.height
@interface ViewController ()
/**lab*/
@property (nonatomic,strong)  UILabel *textlab ;
/**数据源*/
@property (nonatomic,strong) NSMutableArray  * dataArray;
@property (nonatomic,strong) NSTimer *timer;
@end

@implementation ViewController

#pragma mark - 懒加载
- (NSMutableArray *)dataArray
{
    if (!_dataArray) {
        self.dataArray = [[NSMutableArray alloc]init];
    }
    return _dataArray;
}
- (void)viewDidLoad {
    [super viewDidLoad];

//    self.dataArray = @[@"张杰",@刘亦菲",@"赵丽颖",@"刘若英",@"张惠妹",@"范冰冰冰"].mutableCopy;
    
    UIButton *startBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    startBtn.frame = CGRectMake(50, 100,  kScreenW -100 ,30);
    startBtn.backgroundColor = [UIColor redColor];
    [startBtn setTitle:@"开始" forState:UIControlStateNormal];
    [startBtn addTarget:self action:@selector(startAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:startBtn];
    
    
    UIButton *stopBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  stopBtn.frame = CGRectMake(50, 200,  kScreenW -100 ,30);
    stopBtn.backgroundColor = [UIColor orangeColor];
    [stopBtn setTitle:@"结束" forState:UIControlStateNormal];
    [stopBtn addTarget:self action:@selector(stopBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:stopBtn];
    UILabel *title = [[UILabel alloc]initWithFrame:CGRectMake(10, 260,  100 ,30)];
    title.text = @"今日中奖:";
    [self.view addSubview:title];
    self.textlab.textAlignment = NSTextAlignmentCenter;
    _textlab.backgroundColor = [UIColor grayColor];
    [self.view addSubview:_textlab];
    self.textlab = [[UILabel alloc]initWithFrame:CGRectMake(120, 260,  kScreenW -240 ,30)];
    self.textlab.textColor = [UIColor redColor];
    self.textlab.textAlignment = NSTextAlignmentCenter;

    [self.view addSubview:_textlab];
    
   }

#pragma mark 点击事件
- (void)startAction:(UIButton *)sender
{
    [_timer invalidate];
    NSLog(@"开始");
    // 创建定时器
    self.timer = [NSTimer scheduledTimerWithTimeInterval:0.08 target:self selector:@selector(timerAction) userInfo:nil repeats:YES];
    
}

- (void)stopBtnAction:(UIButton *)sender
{
    NSLog(@"结束");
    
    [_timer invalidate];

}
- (void)timerAction{

    int  y =  0 + arc4random()%(100 - 0 + 1);
    self.textlab.text =[NSString stringWithFormat:@"%d",y];
    //    self.dataArray = @[@"张杰",@刘亦菲",@"赵丽颖",@"刘若英",@"张惠妹",@"范冰冰"].mutableCopy;
    //  self.textlab.text = self.dataArray[y];
}

@end

相关文章

  • iOS 摇号

    代码不多就不提供demo了,直接贴代码,供娱乐!

  • 摇号 摇号!

    一大早就收到了一众微信公众号发布的,洛阳市民办小学中学可以网络报名的消息。 今年,洛阳市的20所民办小学、22所民...

  • 摇号

    阴曹地府历某月26号! “中了吗?”老死鬼笑嘻嘻地问身旁的饿死鬼。 “没有,我今天第一次摇,还没收到消息,看来是没...

  • 摇号!!!

    如今的杭州疯了! 几万人抢房子,户型不看,位置不看,大概一了解,看在大家都摇的面子上,就跟着摇了! 登记过程中是一...

  • 摇号

    今天摇号,看到他,人群中非常普通,不复从前在我面前的自信。我笃定地跟程序走,不再在乎他是否看到我,会有什么想法。昨...

  • 摇号

    “明天是摇号日,微博里有人烧香拜佛求中签…” “什么样的?给我看看” “为摇号网友真是绞尽脑汁啊” “我也烧一炷香...

  • 摇号

    今天给大姐大报了青少年宫的美术初级培训课,能否报名成功,看运气,摇号。 以前只听说买房要摇号,后来知道上车牌也要摇...

  • 摇号

    8月5日晚上19:22分,幼儿园的公众号发布了一条信息,名单已经出来贴在了学校北门上。20:00的时候我看到了这条...

  • 摇号

    西溪公馆的结果出来了,圈内水蒸气又摇中了,天选之子啊,羡慕得质壁分离。 其他的大部分是陪跑的,而我只能作为吃瓜群众...

  • 摇号

    富阳民办初中“摇号”结果公布!你家孩子被录取了吗?

网友评论

    本文标题:iOS 摇号

    本文链接:https://www.haomeiwen.com/subject/hupxxxtx.html