NSPredicate用法之一: 数组元素为对象时,通过对象的某个属性快速筛选出数组中的对象
// 找出tips和年报的模型
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"type == 1001 OR type == 1002"];
NSArray *temp = [self.dataArray filteredArrayUsingPredicate:predicate];
if (temp.count > 0) {
_hasTips = YES;
} else {
_hasTips = NO;
}
关于NSPredicate更多高级用法,参见:iOS NSPredicate 使用详解
iOS中的谓词(NSPredicate)使用
SD图片加载渐现效果
[_ImageView sd_setImageWithURL:url placeholderImage:placeholderImage options:YYWebImageOptionAllowBackgroundTask progress:^(NSInteger receivedSize, NSInteger expectedSize, NSURL * _Nullable targetURL) {
dispatch_sync(dispatch_get_main_queue(), ^(){
[weakSelf fadeLayer:weakSelf.ImageView.layer];
});
} completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
}];
- (void)fadeLayer:(CALayer *)layer {
CATransition *transition = [CATransition animation];
transition.duration = 0.5;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionFade;
[layer addAnimation:transition forKey:@"fade"];
}
使用pandoc为markdown生成大纲
- 下载和安装pandoc
下载地址https://github.com/jgm/pandoc/releases
Mac系统直接下载pandoc-2.5-macOS.pkg双击安装即可
- 下载和安装pandoc
- 打开终端,输入
pandoc --version
确认 pandoc 已成功安装
- 打开终端,输入
pandoc 2.5
Compiled with pandoc-types 1.17.5.4, texmath 0.11.1.2, skylighting 0.7.4
Default user data directory: /Users/wanghaobing/.pandoc
Copyright (C) 2006-2018 John MacFarlane
Web: http://pandoc.org
- 3.
cd
到存放.md
文件的文件夹目录 - 输入
pandoc -s --toc README.md -o README.md
命令,即可自动生成目录 (使用该命令默认生成三级目录)
如果想要生成4级目录,可以使用pandoc -s --toc --toc-depth=4 README.md -o README.md
命令 (README.md可以修改为你的markdown文件名)
- 输入
WKWebView头部添加自定义View, 随Webview一起滚动
WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc] init];
WKWebView *webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight) configuration:configuration];
webView.navigationDelegate = self;
webView.multipleTouchEnabled = YES;
webView.userInteractionEnabled = YES;
webView.contentMode = UIViewContentModeScaleAspectFit;
webView.scrollView.scrollEnabled = YES;
webView.scrollView.delegate = self;
// 调整contentInset,将自定义视图添加到webView.scrollView
webView.scrollView.contentInset = UIEdgeInsetsMake(ScreenWidth, 0, 0, 0);
CustomView *customView = [[CustomView alloc] initWithFrame:CGRectMake(0, -ScreenWidth, ScreenWidth, ScreenWidth)]; //注意y值.
[webView.scrollView addSubview: customView];
[self.view addSubview:webView];
获取当天,当周,当月,当年的时间区间
double interval = 0;
NSDate *beginDate = nil;
NSDate *endDate = nil;
NSCalendar *calendar = [NSCalendar currentCalendar];
[calendar setFirstWeekday:2];//设定周一为周首日
BOOL exist = [calendar rangeOfUnit:NSCalendarUnitWeekOfYear startDate:&beginDate interval:&interval forDate:[NSDate date]];
// unit可分别修改为 NSCalendarUnitDay NSCalendarUnitWeekOfYear NSCalendarUnitMonth NSCalendarUnitYear
if (exist) {
endDate = [beginDate dateByAddingTimeInterval:interval-1];
}else {
return [NSArray array];
}
NSDateFormatter *myDateFormatter = [[NSDateFormatter alloc] init];
[myDateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSString *beginString = [myDateFormatter stringFromDate:beginDate];
NSString *endString = [myDateFormatter stringFromDate:endDate];
NSString *section = [NSString stringWithFormat:@"%@ ~ %@",beginString,endString];
NSLog(@"%@",section); // 2018-11-12 00:00:00 ~ 2018-11-18 23:59:59
当然,将上述方法中的 rangeOfUnit
替换为:
-
NSCalendarUnitDay
可以获取当天的时间区间2018-11-12 00:00:00 ~ 2018-11-12 23:59:59
-
NSCalendarUnitWeekOfYear
可以获取当周的时间区间2018-11-12 00:00:00 ~ 2018-11-18 23:59:59
-
NSCalendarUnitMonth
可以获取当月的时间区间2018-11-01 00:00:00 ~ 2018-11-30 23:59:59
-
NSCalendarUnitYear
可以获取当年的时间区间2018-01-01 00:00:00 ~ 2018-12-31 23:59:59
iOS 11以后系统相册选取完图片编辑页面,取消按钮很难被点击到的问题解决办法
#pragma mark - Navigation Controller Delegate
- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
if ([UIDevice currentDevice].systemVersion.floatValue < 11) {
return;
} if ([viewController isKindOfClass:NSClassFromString(@"PUPhotoPickerHostViewController")]) {
[viewController.view.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
// iOS 11之后,图片编辑界面最上层会出现一个宽度<42的view,会遮盖住左下方的cancel按钮,使cancel按钮很难被点击到,故改变该view的层级结构
if (obj.frame.size.width < 42) {
[viewController.view sendSubviewToBack:obj];
*stop = YES;
}
}];
}
}
创建一个可任意伸缩的图片
- (UIImage *)stretchableImageWithLeftCapWidth:(NSInteger)leftCapWidth topCapHeight:(NSInteger)topCapHeight
-
这是 UIImage 的一个实例方法,它的功能是创建一个内容可拉伸,而边角不拉伸的图片,需要两个参数,第一个是左边不拉伸区域的宽度,第二个参数是上面不拉伸的高度。根据设置的宽度和高度,将接下来的一个像素进行左右扩展和上下拉伸。
-
注意:可拉伸的范围都是距离leftCapWidth后的1竖排像素,和距离topCapHeight后的1横排像素
Article list
网友评论