• iOS常用技术-七彩方块


     1 //
     2 //  UIColor+Radom.h
     3 //  七彩方块
     4 //
     5 //  Created by 大欢 on 16/1/18.
     6 //  Copyright © 2016年 bjsxt. All rights reserved.
     7 //
     8 
     9 #import <UIKit/UIKit.h>
    10 
    11 @interface UIColor (Radom)
    12 
    13 + (UIColor *)Random;
    14 
    15 @end

    /***************************************************/

     1 //
     2 //  UIColor+Radom.m
     3 //  七彩方块
     4 //
     5 //  Created by 大欢 on 16/1/18.
     6 //  Copyright © 2016年 bjsxt. All rights reserved.
     7 //
     8 
     9 #import "UIColor+Radom.h"
    10 
    11 @implementation UIColor (Radom)
    12 
    13 + (UIColor *)Random {
    14     
    15     NSInteger r = arc4random()%255;
    16     NSInteger g = arc4random()%255;
    17     NSInteger b = arc4random()%255;
    18     NSInteger a = arc4random()%10;
    19 
    20     return [UIColor colorWithRed:r/255.0f green:g/255.0f blue:b/255.0f alpha:a/10.0f];
    21 }
    22 
    23 @end

    /**************************************************************/

     1 //
     2 //  ViewController.m
     3 //  七彩方块
     4 //
     5 //  Created by 大欢 on 16/1/18.
     6 //  Copyright © 2016年 bjsxt. All rights reserved.
     7 //
     8 
     9 #import "ViewController.h"
    10 #import "UIColor+Radom.h"
    11 
    12 @interface ViewController ()
    13 
    14 @end
    15 
    16 @implementation ViewController
    17 
    18 - (void)viewDidLoad {
    19     [super viewDidLoad];
    20    
    21     [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(addColorBlock) userInfo:nil repeats:YES];
    22     
    23 }
    24 
    25 - (void)addColorBlock {
    26     
    27     UIView * v = [[UIView alloc] init];
    28     v.frame = CGRectMake([self randomVar1], [self randomVar2], [self randomSize], [self randomSize]);
    29     v.backgroundColor = [UIColor Random];
    30     [self.view addSubview:v];
    31 }
    32 
    33 - (NSInteger)randomVar1 {
    34     return arc4random()%400;
    35 }
    36 
    37 - (NSInteger)randomVar2 {
    38     return arc4random()%700;
    39 }
    40 
    41 - (NSInteger)randomSize {
    42     return arc4random()%100 + 50;
    43 }
    44 
    45 - (void)didReceiveMemoryWarning {
    46     [super didReceiveMemoryWarning];
    47     // Dispose of any resources that can be recreated.
    48 }
    49 
    50 @end


  • 相关阅读:
    后缀自动机/回文自动机/AC自动机/序列自动机----各种自动机(自冻鸡) 题目泛做
    BZOJ 1001 狼抓兔子 (网络流最小割/平面图的对偶图的最短路)
    FFT与多项式、生成函数题目泛做
    BZOJ 2243 SDOI 2011染色
    莫队/分块 题目泛做
    Cogs 12 运输问题2 (有上下界网络流)
    可并堆/左偏树 题目泛做
    TC快速搜索在win10下不可用
    (转)Tomcat调优
    (转)Tomcat文件详解
  • 原文地址:https://www.cnblogs.com/MrWuYindi/p/5146494.html
Copyright © 2020-2023  润新知