新增夺宝精灵

This commit is contained in:
liyuhua
2023-08-10 10:12:19 +08:00
parent 00e4fd98bd
commit 8bda1a7f8a
482 changed files with 16034 additions and 440 deletions

View File

@@ -1,14 +1,15 @@
//
// UIButton+EnlargeTouchArea.h
// YMCategrayKit
// XCCategrayKit
//
// Created by YM on 2022/8/30.
// Copyright © 2018年 YUIMI. All rights reserved.
// Created by Macx on 2018/8/30.
// Copyright © 2018年 KevinWang. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface UIButton (EnlargeTouchArea)
@property (nonatomic, assign) NSTimeInterval yn_acceptEventInterval; // 重复点击的间隔
//图片frmae
@property (strong, nonatomic) NSValue *imageFrame;
@@ -33,4 +34,7 @@
*/
- (void)enlargeTouchArea:(UIEdgeInsets)insets;
+(UIButton *)buttonInitWithText:(NSString *)text font:(UIFont *)font textColor:(UIColor *)textColor image:(UIImage *)image bgImage:(UIImage *)bgImage;
@end

View File

@@ -1,16 +1,26 @@
//
// UIButton+EnlargeTouchArea.m
// YMCategrayKit
// XCCategrayKit
//
// Created by YM on 2022/8/30.
// Copyright © 2018 YUIMI. All rights reserved.
// Created by Macx on 2018/8/30.
// Copyright © 2018 KevinWang. All rights reserved.
//
#import "UIButton+EnlargeTouchArea.h"
#import <objc/runtime.h>
#define defaultInterval 0.0003 //,
@interface UIButton ()
/**
* bool YES NO
*/
@property (nonatomic, assign) BOOL isIgnoreEvent;
@end
@implementation UIButton (EnlargeTouchArea)
static const char *UIControl_acceptEventInterval = "UIControl_acceptEventInterval";
static const char *UIControl_enventIsIgnoreEvent = "UIControl_enventIsIgnoreEvent";
// C
static const char *imageFrameStr = "imageFrame";
@@ -26,9 +36,54 @@ static const char *titleFrameStr = "titleFrame";
Method newTitleMethod = class_getInstanceMethod(self, @selector(new_titleRectForContentRect:));
Method oldTitleMethod = class_getInstanceMethod(self, @selector(titleRectForContentRect:));
method_exchangeImplementations(newTitleMethod, oldTitleMethod);
//selectorMethod
SEL selA = @selector(sendAction:to:forEvent:);
SEL selB = @selector(new_sendAction:to:forEvent:);
Method methodA = class_getInstanceMethod(self,selA);
Method methodB = class_getInstanceMethod(self, selB);
//
BOOL isAdd = class_addMethod(self, selA, method_getImplementation(methodB), method_getTypeEncoding(methodB));
if (isAdd) {//->
class_replaceMethod(self, selB, method_getImplementation(methodA), method_getTypeEncoding(methodA));
}else{//->
// methodBmethodAmethodBIMP
method_exchangeImplementations(methodA, methodB);
}
});
}
- (void)new_sendAction:(SEL)action to:(id)target forEvent:(UIEvent *)event {
self.yn_acceptEventInterval = self.yn_acceptEventInterval == 0 ? defaultInterval : self.yn_acceptEventInterval;
if (self.isIgnoreEvent){//
return;
}
if (self.yn_acceptEventInterval > 0){//eventTimeInterval
[self performSelector:@selector(setNoIgnoreEvent) withObject:nil afterDelay:self.yn_acceptEventInterval];
}
self.isIgnoreEvent = YES;//
[self new_sendAction:action to:target forEvent:event];
}
// runtime
- (BOOL)isIgnoreEvent{
return [objc_getAssociatedObject(self, UIControl_enventIsIgnoreEvent) boolValue];
}
-(void)setNoIgnoreEvent{
self.isIgnoreEvent = NO;
}
- (void)setIsIgnoreEvent:(BOOL)isIgnoreEvent {
objc_setAssociatedObject(self, UIControl_enventIsIgnoreEvent, @(isIgnoreEvent), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
-(void)setYn_acceptEventInterval:(NSTimeInterval)yn_acceptEventInterval{
objc_setAssociatedObject(self, UIControl_acceptEventInterval, @(yn_acceptEventInterval), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
-(NSTimeInterval)yn_acceptEventInterval{
return [objc_getAssociatedObject(self, UIControl_acceptEventInterval) doubleValue];
}
- (void)setImageFrame:(NSValue *)imageFrame{
objc_setAssociatedObject(self, imageFrameStr, imageFrame, OBJC_ASSOCIATION_RETAIN);
}
@@ -111,5 +166,27 @@ static char leftNameKey;
}
return CGRectContainsPoint(rect, point) ? self : nil;
}
+(UIButton *)buttonInitWithText:(NSString *)text font:(UIFont *)font textColor:(UIColor *)textColor image:(UIImage *)image bgImage:(UIImage *)bgImage{
UIButton *button = [[UIButton alloc]initWithFrame:CGRectZero];
if(text.length > 0){
[button setTitle:text forState:UIControlStateNormal];
}
if(font != nil){
button.titleLabel.font = font;
}
if(textColor != nil){
[button setTitleColor:textColor forState:UIControlStateNormal];
}
if (image != nil){
[button setImage:image forState:UIControlStateNormal];
}
if(bgImage != nil){
[button setBackgroundImage:bgImage forState:UIControlStateNormal];
}
return button;
}
@end