//随机色
#define random(r, g, b, a) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:(a)/255.0]
#define randomColor random(arc4random_uniform(256), arc4random_uniform(256), arc4random_uniform(256), arc4random_uniform(256))
- (void)viewDidLoad {
[super viewDidLoad];
for (int i = 0; i < 3; i ++) {
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(20 + (100 + 17) * i, 100, 100, 50)];
view.backgroundColor = [UIColor greenColor];
view.tag = 10 + i;
[self.view addSubview:view];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(getViewTag:)];
[view addGestureRecognizer:tap];
}
}
- (void)getViewTag:(UITapGestureRecognizer *)sender{
UIView *getView = sender.view;
NSLog(@"%ld", getView.tag);
getView.backgroundColor = randomColor;
}
网友评论