ios软件开发 获取手势点击视图的tag

来源:互联网 发布:怎么软件可以赚钱 编辑:程序博客网 时间:2024/05/22 17:43

代码实现如下:

- (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{   <span style="color:#ff6666;"> UIView *getView = sender.view;</span>    NSLog(@"%ld", getView.tag);    getView.backgroundColor = [UIColor cyanColor];}

0 0
原创粉丝点击