Skip to content

Instantly share code, notes, and snippets.

@dhl613
dhl613 / UINavigationBar+ItemEvent.m
Created March 9, 2019 03:20
解决导航栏按钮(返回)响应区域过大问题
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
if ([self pointInside:point withEvent:event]) {
self.userInteractionEnabled = YES;
} else {
self.userInteractionEnabled = NO;
}
@dhl613
dhl613 / FirstFrameOfVideo.m
Created February 25, 2019 07:18
获取视频缩略图
/// 方法一:MPMoviePlayerController
NSString *videoURL = @"http:// or /private(local video)"
NSURL *URL = [NSURL URLWithString: videoURL];
// NSURL *URL = [NSURL fileURLWithPath:videoURL]
MPMoviePlayerController *iosMPMovie = [[MPMoviePlayerController alloc]initWithContentURL:URL]; iosMPMovie.shouldAutoplay = NO;
UIImage *thumbnail = [iosMPMovie thumbnailImageAtTime:time timeOption:MPMovieTimeOptionNearestKeyFrame];
/// 方法二:AVAssetImageGenerator
+ (UIImage *)getThumbnailImage:(NSString *)videoURL {
@dhl613
dhl613 / UIAlertController+HLTapDismiss.m
Created January 16, 2019 08:20
UIAlertController添加点击空白dismiss手势
#import "UIAlertController+JHTapDismiss.h"
@interface UIAlertController ()<UIGestureRecognizerDelegate>
@end
@implementation UIAlertController (JHTapDismiss)
- (void)alertTapDismiss {
@dhl613
dhl613 / UILabelLayoutSideBySide.m
Last active December 6, 2019 09:29
UILabel 并排 自适应 显示
“Content Hugging Priority”,也叫内容紧靠优先级(小名:别扯我),该优先级越高,这越晚轮到被拉伸。
“Content Compression Resistance Priority”,也叫内容压缩阻力优先级(小名:别挤我),该优先级越高,则越晚轮到被压缩。
// ⤴️原文: https://www.jianshu.com/p/a4b8e0c8e68d
// 紧靠能力 优先级越低 内容显示得越完整 反之,内容被省略
[self.nameLabel setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
[self.priceLabel setContentHuggingPriority:UILayoutPriorityDefaultLow forAxis:UILayoutConstraintAxisHorizontal];
@dhl613
dhl613 / arrayGrouping.m
Created July 20, 2018 03:50
iOS 数组归类分组 数组以年分组
/// 待分组数据 以年为单位分组
NSMutableArray *data = [NSMutableArray array];
for (int i = 2018; i > 2010; i--) {
NSString *typeValue = [NSString stringWithFormat:@"%d",i];
for (int j = 1; j < 5; j++) {
NSString *other = [NSString stringWithFormat:@"月份: %d",j+(arc4random() % 5)];
[data addObject:@{@"year":typeValue,@"month":other}];
}
}
@dhl613
dhl613 / scrollView.m
Last active June 9, 2018 10:01
UIScrollView下拉刷新跳动
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset {
CGFloat y = scrollView.contentOffset.y;
if (y < -65) {
[self.collectionView.mj_header beginRefreshing];
// 消除刷新时functionView跳动的问题 动画时间不低于0.25s
UIEdgeInsets inset = scrollView.contentInset;
dispatch_async(dispatch_get_main_queue(), ^{
[UIView animateWithDuration:0.25 animations:^{
@dhl613
dhl613 / MD5.swift
Last active April 18, 2018 02:27
MD5编码代码片段 OC实现 Swift实现
#### OC版
/// #import <CommonCrypto/CommonDigest.h>
/// (Category)
- (NSString *)md5 {
const char *str = [self UTF8String];
if (str == NULL) {
str = "";
}
unsigned char r[CC_MD5_DIGEST_LENGTH];