addSubView到UIButton

Jos*_*Jos 44 iphone objective-c uibutton addsubview ios

我正在尝试将子视图添加到UIButton.这个工作正常.但是,只要我添加子视图,该按钮就不再可以点击了.

我使用以下代码:

UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(column*100+24, row*80+10, 64, 64);
[button addSubview:asyncImage];
[button addSubview:price];
    [button addTarget:self 
               action:@selector(buttonClicked:) 
     forControlEvents:UIControlEventTouchUpInside];
Run Code Online (Sandbox Code Playgroud)

如果我删除了2个addsubviews,那么该按钮将再次起作用.如果有人知道如何解决这个问题那就太棒了!

日Thnx !!!

Jos*_*Jos 75

我找到了一个快速解决方案 我需要将asyncimageview设置为以下内容:

asyncImage.userInteractionEnabled = NO;
        asyncImage.exclusiveTouch = NO;
Run Code Online (Sandbox Code Playgroud)

在此之后它工作了!

  • 只需设置“userInteractionEnabled = false”即可解决我的问题。 (2认同)