Skip to content

Instantly share code, notes, and snippets.

View hanfengs's full-sized avatar

hanfengs

  • Beijing China
View GitHub Profile
@hanfengs
hanfengs / compare.m
Created July 12, 2019 01:57
[版本号比较] 版本号比较oc实现
/**
@return 如果版本号相等返回0,第一个版本号高于第二个,返回1,否则返回 -1.
*/
- (NSInteger)compareVersion:(NSString *)version1 andVersion:(NSString *)version2{
NSInteger res = 0;
NSArray *arry1 = [version1 componentsSeparatedByString:@"."];
NSArray *arry2 = [version2 componentsSeparatedByString:@"."];
NSInteger idx1 = 0;
NSInteger idx2 = 0;
@hanfengs
hanfengs / url.m
Created July 16, 2019 06:30
[截取url中的参数]
/**
* 截取URL中的参数
*
* @return NSMutableDictionary parameters
*/
+ (NSMutableDictionary *)getURLParameters:(NSString *)urlStr {
// 查找参数
NSRange range = [urlStr rangeOfString:@"?"];
if (range.location == NSNotFound) {
@hanfengs
hanfengs / nsurl.m
Created July 16, 2019 06:37
[NSURL 的解析和编码]
//https://quxue-data.oss-cn-beijing.aliyuncs.com/scene_course/reading/baowei/reading12-3-73.json
NSURL *url = [NSURL URLWithString:jsonUrl];
NSLog(@"Scheme: %@", [url scheme]);//https
NSLog(@"Host: %@", [url host]);//https
NSLog(@"Port: %@", [url port]);//null
NSLog(@"Path: %@", [url path]);//scene_course/reading/baowei/reading12-3-73.json
NSLog(@"Relative path: %@", [url relativePath]);//scene_course/reading/baowei/reading12-3-73.json
/*
Path components as array: (
@hanfengs
hanfengs / getOSS.m
Last active July 16, 2019 09:01
[阿里云OSS方式下载文件]
/*
阿里云出于安全考虑,从2018年8月13日起,直接使用OSS访问域名,从互联网访问OSS上的网页类型文件(mimetype为text/html,扩展名包括htm、 html、jsp、plg、htx 和stm)时,Response Header中会自动加上 Content-Disposition:'attachment=filename;'。即从浏览器访问网页类型文件时,会以附件 形式进行下载。
用户使用自有域名访问OSS的请求,Response Header中不会加上此信息。如何使用自有域名访问OSS,请参考OSS帮助文档“绑定自定义域名”。
表现的现象是, web中下载文件时,我们一般设置Content-Disposition告诉浏览器下载文件的名称,是否在浏览器中内嵌显示.
Content-disposition: inline; filename=1502849449726.jpg表示浏览器内嵌显示一个文件
Content-disposition: attachment; filename=1502849449726.xlsx表示会下载文件,如火狐浏览器中
@hanfengs
hanfengs / json.m
Last active July 19, 2019 10:49
[本地读取json数据]
NSString *jsonPath = [[NSBundle mainBundle] pathForResource:@"json" ofType:@"json"];
NSData *data = [NSData dataWithContentsOfFile:jsonPath];
NSError *error = nil;
id result = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&error];
NSLog(@"\n%@====%@", [error localizedDescription], result);
TSSentencePracticeResultModel *resu = [TSSentencePracticeResultModel yy_modelWithJSON:result];
NSLog(@"====%@", resu);
self.dataArr = [self checkDataArr:resu.result.wordPracticeList];
@hanfengs
hanfengs / re.m
Created July 23, 2019 01:33
[滑动手势]
UISwipeGestureRecognizer *recognizer = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(handleSwipeFrom:)];
[recognizer setDirection:(UISwipeGestureRecognizerDirectionLeft)];
[self.view addGestureRecognizer:recognizer];
- (void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer{
if(recognizer.direction == UISwipeGestureRecognizerDirectionDown) {
NSLog(@"swipe down");
}
if(recognizer.direction == UISwipeGestureRecognizerDirectionUp) {
@hanfengs
hanfengs / idx.m
Last active August 1, 2019 05:22
[获取字符串中多个相同字符的位置index]
#pragma mark - 获取这个字符串ASting中的所有abc的所在的index
- (NSMutableArray *)getRangeStr:(NSString *)text findText:(NSString *)findText
{
NSMutableArray *arrayRanges = [NSMutableArray arrayWithCapacity:3];
if (findText == nil && [findText isEqualToString:@""])
{
return nil;
@hanfengs
hanfengs / fangzhou.md
Created August 7, 2019 01:44
[方舟编译器]

早上地铁的时间就看了这一篇文章《方舟编译器的荣光和使命》,总结一下:

安卓的四大问题

1;java虚拟机+编译器+解释器,应用安装或者空闲编译,在手机上生成二进制的机器码

2;额外的JNI开销,用于和C/C++代码交互,

3;代码优化空间有限,为了防止生态过于碎片化,为第三方开放了简单的优化

@hanfengs
hanfengs / btn.m
Created August 14, 2019 10:54
[UIButton文字和图片间距随意调整]
UIButton category
-----------------------------------------.h
// 定义一个枚举(包含了四种类型的button)
typedef NS_ENUM(NSUInteger, GLButtonEdgeInsetsStyle) {
GLButtonEdgeInsetsStyleTop, // image在上,label在下
GLButtonEdgeInsetsStyleLeft, // image在左,label在右
GLButtonEdgeInsetsStyleBottom, // image在下,label在上
GLButtonEdgeInsetsStyleRight // image在右,label在左
};
@hanfengs
hanfengs / op.m
Created August 20, 2019 09:23
[多选项(4或者更多),自动布局]
UIImageView *lastIV = nil;
self.ivArrM = [NSMutableArray array];
for (NSInteger i = 0; i < 4; i++) {
UIImageView *iv = [[UIImageView alloc] init];
[self addSubview:iv];
[iv mas_makeConstraints:^(MASConstraintMaker *make) {
if (isPad) {
make.width.mas_equalTo(163);
}else{
make.width.equalTo(self).multipliedBy(0.5).offset(-IVMragin16 * 1.5);