iOS 搖號(hào)

代碼不多就不提供demo了,直接貼代碼,供娛樂(lè)!

搖號(hào).gif
//
//  ViewController.m
//  搖號(hào)
//
//  Created by 紀(jì)高飛 on 17/5/13.
//  Copyright ? 2017年 紀(jì)高飛. 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 ;
/**數(shù)據(jù)源*/
@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:@"開(kāi)始" 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:@"結(jié)束" 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 = @"今日中獎(jiǎng):";
    [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 點(diǎn)擊事件
- (void)startAction:(UIButton *)sender
{
    [_timer invalidate];
    NSLog(@"開(kāi)始");
    // 創(chuàng)建定時(shí)器
    self.timer = [NSTimer scheduledTimerWithTimeInterval:0.08 target:self selector:@selector(timerAction) userInfo:nil repeats:YES];
    
}

- (void)stopBtnAction:(UIButton *)sender
{
    NSLog(@"結(jié)束");
    
    [_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

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • Android 自定義View的各種姿勢(shì)1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 179,030評(píng)論 25 709
  • 發(fā)現(xiàn) 關(guān)注 消息 iOS 第三方庫(kù)、插件、知名博客總結(jié) 作者大灰狼的小綿羊哥哥關(guān)注 2017.06.26 09:4...
    肇東周閱讀 15,300評(píng)論 4 61
  • 姓名:魏正君《六項(xiàng)精進(jìn)》第270期感謝2組 公司:綿陽(yáng)大北農(nóng)農(nóng)牧科技有限公司 【日精進(jìn)打卡第74天】 【知~學(xué)習(xí)】...
    莫心莫肺閱讀 198評(píng)論 0 0
  • 今天分享的書(shū)是《改變你的服裝,改變你的生活》作者 [美] 喬治·布雷西亞 每次我回家,姐姐都會(huì)說(shuō)我,上海的村姑回來(lái)...
    任清清閱讀 506評(píng)論 2 4

友情鏈接更多精彩內(nèi)容