美文网首页
ios UIImageView添加广告图片点击跳转

ios UIImageView添加广告图片点击跳转

作者: 行走的风车 | 来源:发表于2016-07-14 16:10 被阅读79次
    for (int i = 0; i < totalCount; i++) {
        UIImageView *imageView = [[UIImageView alloc] init];
        //        图片X
        CGFloat imageX = i * imageW;
        //        设置frame
        imageView.frame = CGRectMake(imageX, imageY, imageW, imageH);
        //        设置图片
        NSString *name = [NSString stringWithFormat:@"公交宣传语%d.jpg", i + 1];
        
        imageView.image = [UIImage imageNamed:name];
        imageView.tag = i;
        imageView.userInteractionEnabled=YES;
        UITapGestureRecognizer *singleTap =[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(onClickImage:)];
        [imageView addGestureRecognizer:singleTap];
        
        //imageView.contentMode = UIViewContentModeScaleAspectFit;
        //        隐藏指示条
        self.scrollview.showsHorizontalScrollIndicator = NO;
        
        [self.scrollview addSubview:imageView];
    }
    
    
    
    -(void)onClickImage:(UITapGestureRecognizer *)recognizer
    {
        UIImageView* imageView = (UIImageView*)[recognizer view];
        for (int i=0; i<4; i++) {
            if(imageView.tag == i)
                NSLog(@"图片%d被点击!",i);
        } 
    }

    相关文章

      网友评论

          本文标题:ios UIImageView添加广告图片点击跳转

          本文链接:https://www.haomeiwen.com/subject/xvwejttx.html