Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>UIImageView turns off userInteraction - turn it on and the button will work.</p> <p>EDIT:</p> <p>So I used your code almost exactly as written - the one red herring is that you said it all appears fine. For me, the custom button had a frame of 0,0,0,0 so I saw nothing. When I set the frame it all worked perfectly:</p> <pre><code> UIButton *back = [UIButton buttonWithType:UIButtonTypeCustom]; UIImage *image = [UIImage imageNamed:@"46-truck.png"]; assert(image); [back setImage:image forState:UIControlStateNormal]; [back addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside]; back.showsTouchWhenHighlighted = YES; back.frame = (CGRect){ {0,0}, image.size}; NSLog(@"FRAME: %@", NSStringFromCGRect(back.frame) ); [imageView addSubview:back]; </code></pre> <p>So, if you need to probe the superviews during run time to figure out what is what, you can use this code below. [UIView dumpSuperviews:back msg:@"Darn Bark Button"];</p> <pre><code>@interface UIView (Utilities_Private) + (void)appendView:(UIView *)v toStr:(NSMutableString *)str; @end @implementation UIView (Utilities_Private) + (void)appendView:(UIView *)a toStr:(NSMutableString *)str { [str appendFormat:@" %@: frame=%@ bounds=%@ layerFrame=%@ tag=%d userInteraction=%d alpha=%f hidden=%d\n", NSStringFromClass([a class]), NSStringFromCGRect(a.frame), NSStringFromCGRect(a.bounds), NSStringFromCGRect(a.layer.frame), a.tag, a.userInteractionEnabled, a.alpha, a.isHidden ]; } @end @implementation UIView (Utilities) + (void)dumpSuperviews:(UIView *)v msg:(NSString *)msg { NSMutableString *str = [NSMutableString stringWithCapacity:256]; while(v) { [self appendView:v toStr:str]; v = v.superview; } [str appendString:@"\n"]; NSLog(@"%@:\n%@", msg, str); } + (void)dumpSubviews:(UIView *)v msg:(NSString *)msg { NSMutableString *str = [NSMutableString stringWithCapacity:256]; if(v) [self appendView:v toStr:str]; for(UIView *a in v.subviews) { [self appendView:a toStr:str]; } [str appendString:@"\n"]; NSLog(@"%@:\n%@", msg, str); } @end </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload