Skip to content

Instantly share code, notes, and snippets.

View Andrewmika's full-sized avatar
🎯
Focusing

Wanqi Shen Andrewmika

🎯
Focusing
View GitHub Profile
@Andrewmika
Andrewmika / textSize.m
Created August 7, 2019 08:58
cal textSize
[prompt.text boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, 36) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14]} context:nil].size
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
if (self.clipsToBounds || self.hidden || (self.alpha == 0.f)) {
return nil;
}
UIView *view = [super hitTest:point withEvent:event];
if (view) {
return view;
}
for (UIView *subView in self.subviews.reverseObjectEnumerator) {
CGPoint subPoint = [subView convertPoint:point fromView:self];
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { //处理远程通知——应用正在运行 
if(application.applicationState == UIApplicationStateInactive) {
//用户点击通知中心的通知或报警弹窗
[self processRemoteNotification:userInfo];
} else if(application.applicationState == UIApplicationStateBackground) {
//应用在后台,不存在用户交互——只是获取数据 } else {
//应用已经处于激活状态——显示应用内的更新 }
}
-(void)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
#import "NSData+AES.h"
#import <CommonCrypto/CommonCryptor.h>
@implementation NSData (AES)
static Byte ivBuff[] = {}; // 加密向量
+ (NSString *)AES256EncryptWithContent:(NSString *)content key:(NSString *)key
{
//加密
NSData *plainText = [content dataUsingEncoding:NSUTF8StringEncoding];
@Andrewmika
Andrewmika / NSURL+EX
Last active July 19, 2018 03:57
URL extension
- (NSDictionary *)dictQuery {
NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
NSString *str = self.query;
if (str.length && [str rangeOfString:@"="].location != NSNotFound) {
NSArray *keyValuePairs = [str componentsSeparatedByString:@"&"];
for (NSString *keyValuePair in keyValuePairs) {
NSArray *pair = [keyValuePair componentsSeparatedByString:@"="];
// don't assume we actually got a real key=value pair. start by assuming we only got @[key] before checking count
NSString *paramValue = pair.count == 2 ? pair[1] : @"";
// CFURLCreateStringByReplacingPercentEscapesUsingEncoding may return NULL
@Andrewmika
Andrewmika / UIView+EX.h
Created April 16, 2018 03:40
add Bottom Line
#import <UIKit/UIKit.h>
@interface UIView (EX)
@property (nonatomic, strong) UIView *bottomLine; // <##>
- (void)as_addBottomLine;
- (void)as_addBottomLineWithLeftOffset:(CGFloat)leftOffset rightOffset:(CGFloat)rightOffset;
@Andrewmika
Andrewmika / intrinsicContentSize.h
Last active April 16, 2018 03:41
自定义view设置内在大小
static CGSize const kViewSize = {19, 19};
- (void)layoutSubviews {
[super layoutSubviews];
if (!CGSizeEqualToSize(self.bounds.size, [self intrinsicContentSize])) {
[self invalidateIntrinsicContentSize];
}
}
- (CGSize)intrinsicContentSize {