IOS制作大乐透

#import "ViewController.h"

@interface ViewController ()<UIPickerViewDelegate,UIPickerViewDataSource>
@property(retain)UIPickerView * pick;
@property(retain)NSMutableArray * dateSource;
@property(retain)NSMutableArray * dataSource1;
@property(retain)NSTimer * timer;


@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    _pick=[[UIPickerView alloc]init];
    _pick.delegate=self;
    _pick.dataSource=self;
    _pick.showsSelectionIndicator=YES;
    [self.view addSubview:_pick];

    _dateSource=[NSMutableArray new];
    _dataSource1=[NSMutableArray new];
    for (int i=0; i<35; i++) {
        NSString * str=[NSString stringWithFormat:@"%d",i+1];
        NSLog(@"%@",str);
        [_dateSource addObject:str];
    }
    for (int i=0; i<12; i++) {
        NSString * str1=[NSString stringWithFormat:@"%d",i+1];
        [_dataSource1 addObject:str1];
    }
    for (int i=0; i<2; i++) {
        UIButton * btn=[UIButton buttonWithType:UIButtonTypeCustom];
        if (i==0) {
            [btn setTitle:@"开始" forState:UIControlStateNormal];
           [btn addTarget:self action:@selector(start:) forControlEvents:UIControlEventTouchUpInside];

        }else{
            [btn setTitle:@"结束" forState:UIControlStateNormal];
            [btn addTarget:self action:@selector(stop:) forControlEvents:UIControlEventTouchUpInside];
        }
        [btn setTitleColor:[UIColor cyanColor] forState:UIControlStateNormal];
        btn.frame=CGRectMake(50+i*100, 400, 100, 30);
        [self.view addSubview:btn];
    }

}
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 7;
}
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
    if (component<=4) {
        return _dateSource.count;
    }else{
    return _dataSource1.count;
    }
}
-(CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component
{
    return 50;
}

-(CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component
{
    return  40;
}
//设置每一列的内容   返回值是一个字符串

- (nullable NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
    if (component<=4) {
        return _dateSource[row];
    }else{
    return _dataSource1[row];
    }
}
-(void)start:(UIButton *)sender
{
    //_timer=[NSTimer timerWithTimeInterval:0.3 target:self selector:@selector(timer:) userInfo:nil repeats:YES];
    //取消定时器
    [_timer invalidate];
    _timer=[NSTimer scheduledTimerWithTimeInterval:0.25 target:self selector:@selector(timer:) userInfo:nil repeats:YES];
    NSLog(@"1111");
}
-(void)timer:(NSTimer *)sender
{
    [_pick selectRow:0 inComponent:0 animated:NO];
    [_pick selectRow:0 inComponent:1 animated:NO];
    [_pick selectRow:0 inComponent:2 animated:NO];
    [_pick selectRow:0 inComponent:3 animated:NO];
    [_pick selectRow:0 inComponent:4 animated:NO];
    [_pick selectRow:0 inComponent:5 animated:NO];
    [_pick selectRow:0 inComponent:6 animated:NO];

    //开始滚动的时候第八行第0列
    [_pick selectRow:34 inComponent:0 animated:YES];
    [_pick selectRow:34 inComponent:1 animated:YES];
    [_pick selectRow:34 inComponent:2 animated:YES];
    [_pick selectRow:34 inComponent:3 animated:YES];
    [_pick selectRow:34 inComponent:4 animated:YES];
    [_pick selectRow:11 inComponent:5 animated:YES];
    [_pick selectRow:11 inComponent:6 animated:YES];


}
-(void)stop:(UIButton *)sender
{
    [_timer invalidate];
    int i1=arc4random()%35;
    int i2=arc4random()%35;
    int i3=arc4random()%35;
    int i4=arc4random()%35;
    int i5=arc4random()%35;


    int j1=arc4random()%12;
    int j2=arc4random()%12;


    [_pick selectRow:i1 inComponent:0 animated:YES];
    [_pick selectRow:i2 inComponent:1 animated:YES];
    [_pick selectRow:i3 inComponent:2 animated:YES];
    [_pick selectRow:i4 inComponent:3 animated:YES];
    [_pick selectRow:i5 inComponent:4 animated:YES];

    [_pick selectRow:j1 inComponent:5 animated:YES];
    [_pick selectRow:j2 inComponent:6 animated:YES];
    NSLog(@"1122");
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end

这里写图片描述
这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值