Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's a working category implementation. In it's current form, this should only be used in <code>DEBUG</code>. I use this category in conjunction with a function (included below) to test various bits of code when user interaction and timing are important. Again this is only for development/debug purposes and shouldn't be considered for production, hence the <code>#ifdef DEBUG</code> ;)</p> <pre><code>#ifdef DEBUG #import &lt;objc/runtime.h&gt; static char UIButtonBlockKey; @interface UIButton (UIBlockButton) - (void)handleControlEvent:(UIControlEvents)event withBlock:(ActionBlock)block; - (void)callActionBlock:(id)sender; @end @implementation UIButton (UIBlockButton) - (void)handleControlEvent:(UIControlEvents)event withBlock:(ActionBlock)block { objc_setAssociatedObject(self, &amp;UIButtonBlockKey, block, OBJC_ASSOCIATION_COPY_NONATOMIC); [self addTarget:self action:@selector(callActionBlock:) forControlEvents:event]; } - (void)callActionBlock:(id)sender { ActionBlock block = (ActionBlock)objc_getAssociatedObject(self, &amp;UIButtonBlockKey); if (block) { block(); } } @end void DSAddGlobalButton(NSString *title, ActionBlock block) { UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; [button setTitle:title forState:UIControlStateNormal]; [button handleControlEvent:UIControlEventTouchUpInside withBlock:block]; [button sizeToFit]; [button setFrame:(CGRect){{100.0f, 100.0f}, [button frame].size}]; UIView *firstView = [[[[UIApplication sharedApplication] keyWindow] subviews] objectAtIndex:0]; [firstView addSubview:button]; } #endif </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. 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