IOS-random name or lottery game implementation
# Import ViewController. h
@ Interface ViewController ()
{
NSMutableArray * nameList;
UILabel * label;
Nstmer * timer;
}
@ End
@ Implementation ViewController
-(Void) viewDidLoad {
[Super viewDidLoad];
[Self loadData];
Self. view. backgroundColor = [UIColor grayColor];
Label = [[UILabel alloc] initWithFrame: CGRectMake (50,200,275, 50)];
Label. text = @ won't be me;
Label. textAlignment = NSTextAlignmentCenter;
Label. font = [UIFont systemFontOfSize: 30];
Label. textColor = [UIColor orangeColor];
Label. backgroundColor = [UIColor clearColor];
[Self. view addSubview: label];
UIButton * button = [UIButton buttonWithType: UIButtonTypeCustom];
Button. frame = CGRectMake (150,500,100,100 );
[Self. view addSubview: button];
[Button setTitle: @ click me. forState: UIControlStateNormal];
Button. backgroundColor = [UIColor redColor];
Button. layer. cornerRadius = 50;
Button. layer. masksToBounds = YES;
Button. showsTouchWhenHighlighted = YES;
[Button setTitleColor: [UIColor blackColor] forState: UIControlStateNormal];
[Button addTarget: self action: @ selector (push :) forControlEvents: UIControlEventTouchUpInside];
Timer = [NSTimer scheduledTimerWithTimeInterval: 1 target: self selector: @ selector (loadData) userInfo: nil repeats: YES];
[[Nsunloop currentRunLoop] addTimer: timer forMode: NSDefaultRunLoopMode];
Timer. fireDate = [NSDate distantFuture];
}
-(Void) loadData
{
NSUserDefaults * userDefaults = [NSUserDefaults standardUserDefaults];
NameList = [NSMutableArray arrayWithObjects: @ a, @ B, @ c, @ d, @ e, @ f, @ g Jun, @ f, @ gd, @ fv, @ sd, @ f, @ sdf, @ 4 t, @ I red, @ k, @ u, @ I sea, @ ijk, @ k, @ I Lin, @ Yang Xiaoping, @ I, @ ui Fei, @ I Kuan Fu, @ I Wang, @ e Hao, @ I Cheng, @ I wenxing, @ I Shui, @ I Bo, @ tu Jin Kui, @ I, @ Wang e, @ 5j Lai, @ l Kang, @ i8 Qian, @ k. yi, @; long, @ u Bo, @ ol Zhong 6 Hua, @ y Tao, nil];
[UserDefaults setObject: nameList forKey: @ nameList];
[UserDefaults synchronize];
[UserDefaults objectForKey: @ nameList];
Int arcNumber = arc4random () % nameList. count;
Label. text = nameList [arcNumber];
}
-(Void) push :( UIButton *) sender
{
If (sender. selected! = YES ){
Label. textColor = [UIColor clearColor];
[Sender setTitle: @ pause forState: UIControlStateNormal];
// [NameList removeObject: label. text];
Timer. fireDate = [NSDate distantPast];
Sender. selected = YES;
} Else {
Timer. fireDate = [NSDate distantFuture];
Label. textColor = [UIColor blackColor];
[Sender setTitle: @ click me. forState: UIControlStateNormal];
Sender. selected = NO;
}
}
-(Void) showAlertMessage :( NSString *) message
{
UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @ is your message: message delegate: self cancelButtonTitle: @ OK otherButtonTitles: nil, nil];
[Alert show];
}
@ End