This commit is contained in:
Yao
2025-01-11 14:58:16 +08:00
parent f82486e8b0
commit 1095c32599
262 changed files with 62730 additions and 36131 deletions

View File

@@ -0,0 +1,42 @@
//
// UIButton+DSButtonBlock.m
// DSChat
//
// Created by Mac on 2022/6/14.
// Copyright © 2022 DS. All rights reserved.
//
#import "UIButton+DSButtonBlock.h"
#import <objc/runtime.h>
@implementation UIButton (DSButtonBlock)
static char ActionTag;
/**
* button
*/
- (void)addAction:(ButtonBlock)block
{
objc_setAssociatedObject(self, &ActionTag, block, OBJC_ASSOCIATION_COPY_NONATOMIC);
[self addTarget:self action:@selector(action:) forControlEvents:UIControlEventTouchUpInside];
}
/**
* button
*/
- (void)addAction:(ButtonBlock)block forControlEvents:(UIControlEvents)controlEvents
{
objc_setAssociatedObject(self, &ActionTag, block, OBJC_ASSOCIATION_COPY_NONATOMIC);
[self addTarget:self action:@selector(action:) forControlEvents:controlEvents];
}
- (void)action:(id)sender
{
ButtonBlock blockAction = (ButtonBlock)objc_getAssociatedObject(self, &ActionTag);
if (blockAction) {
blockAction(self);
}
}
@end