//
Uicolor+radom.h
Colorful Squares
//
Created by Big Huan on 16/1/18.
COPYRIGHT©2016 year BJSXT. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface Uicolor (Radom)
+ (Uicolor *) Random;
@end
/***************************************************/
//
Uicolor+radom.m
Colorful Squares
//
Created by Big Huan on 16/1/18.
COPYRIGHT©2016 year BJSXT. All rights reserved.
//
#import "Uicolor+radom.h"
@implementation Uicolor (Radom)
+ (Uicolor *) Random {
Nsinteger r = arc4random ()%255;
Nsinteger g = arc4random ()%255;
Nsinteger B = arc4random ()%255;
Nsinteger a = Arc4random ()%10;
return [Uicolor colorwithred:r/255.0f green:g/255.0f blue:b/255.0f alpha:a/10.0f];
}
@end
/**************************************************************/
//
Viewcontroller.m
Colorful Squares
//
Created by Big Huan on 16/1/18.
COPYRIGHT©2016 year BJSXT. All rights reserved.
//
#import "ViewController.h"
#import "Uicolor+radom.h"
@interface Viewcontroller ()
@end
@implementation Viewcontroller
-(void) Viewdidload {
[Super Viewdidload];
[Nstimer scheduledtimerwithtimeinterval:0.5 target:self selector: @selector (addcolorblock) Userinfo:nil Repeats:YES] ;
}
-(void) Addcolorblock {
UIView * v = [[UIView alloc] init];
V.frame = CGRectMake ([self-randomVar1], [self-randomVar2], [self-randomsize], [self randomsize]);
V.backgroundcolor = [Uicolor Random];
[Self.view Addsubview:v];
}
-(Nsinteger) randomVar1 {
Return Arc4random ()%400;
}
-(Nsinteger) randomVar2 {
Return Arc4random ()%700;
}
-(Nsinteger) randomsize {
Return Arc4random ()%100 + 50;
}
-(void) didreceivememorywarning {
[Super didreceivememorywarning];
Dispose of any resources the can be recreated.
}
@end
iOS common technology-colorful squares