iOS -实现imageView中的button响应点击事件的方法

 

  
/**
imageview默认是不响应事件的 ,所以即使在上边加上个button也不会响应;
解决办法是:将这个imageview.userInterfaceEnabled  =   YES
*/

 


eg:-

 

-(void)setUI
{
    int column = COLUMN;
    int gap = ( self.view.frame.size.width - column * yellowViewWidth ) / (column +1);
    if ( gap <= 0) {
        NSLog(@"Column is too big!");
        return;
    }
    for (int i = 0; i < self.arrayDate.count ; i++) {
        
        //add yellowView  and set x y width hight and attribute
        int x = i % column ;
        int y = i / column;
        
        CGFloat yellowX = ( x + 1 ) * gap + x * yellowViewWidth;
        CGFloat yellowY = ( y + 1 ) * gap + y * yellowViewHight;
        
        MyView *yellowView = [[MyView alloc] initWithFrame:CGRectMake(yellowX, yellowY, yellowViewWidth, yellowViewHight)];
        
        MyModel *model = self.arrayDate[i];
        // 为 yellowView 的 appModel进行赋值
        yellowView.model = model;
        
        //NSLog(@"-========= %@",self.arrayDate[i]);
        /**
         imageview默认是不响应事件的 ,所以即使在上边加上个button也不会响应;
         解决办法是:将这个imageview.userInterfaceEnabled  =   YES
         */
        yellowView.userInteractionEnabled = YES;
        [self.view addSubview:yellowView];
    }

}


 

 

 


 

 

转载于:https://www.cnblogs.com/yangsanchao/p/5014476.html

你可能感兴趣的:(iOS -实现imageView中的button响应点击事件的方法)