从身份证号码里提取生日和周岁的方法
575
2022-05-29
判断字符串是不是以中文开头
- (BOOL)isChineseFirst:(NSString *)firstString { //是否以中文开头(unicode中文编码范围是0x4e00~0x9fa5) int utfCode = 0; void *buffer = &utfCode; NSRange range = NSMakeRange(0, 1); //判断是不是中文开头的,buffer->获取字符的字节数据 maxLength->buffer的最大长度 usedLength->实际写入的长度,不需要的话可以传递NULL encoding->字符编码常数,不同编码方式转换后的字节长是不一样的,这里我用了UTF16 Little-Endian,maxLength为2字节,如果使用Unicode,则需要4字节 options->编码转换的选项,有两个值,分别是NSStringEncodingConversionAllowLossy和NSStringEncodingConversionExternalRepresentation range->获取的字符串中的字符范围,这里设置的第一个字符 remainingRange->建议获取的范围,可以传递NULL BOOL isChinese = [firstString getBytes:buffer maxLength:2 usedLength:NULL encoding:NSUTF16LittleEndianStringEncoding options:NSStringEncodingConversionExternalRepresentation range:range remainingRange:NULL]; if (isChinese && (utfCode >= 0x4e00 && utfCode <= 0x9fa5)) return YES; else return NO; }
1
2
3
4
5
6
7
8
9
10
11
12
键盘回收
- (void)setUpForDismissKeyboard { UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAnywhereToDismissKeyboard:)]; NSOperationQueue *operation = [NSOperationQueue mainQueue]; [[NSNotificationCenter defaultCenter] addObserverForName:UIKeyboardWillShowNotification object:nil queue:operation usingBlock:^(NSNotification * _Nonnull note) { [self.view addGestureRecognizer:tapGesture]; }]; [[NSNotificationCenter defaultCenter] addObserverForName:UIKeyboardWillHideNotification object:nil queue:operation usingBlock:^(NSNotification * _Nonnull note) { [self.view removeGestureRecognizer:tapGesture]; }]; }
1
2
3
4
5
6
7
8
9
10
禁止侧滑返回上一个界面
if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) { self.navigationController.interactivePopGestureRecognizer.enabled = NO; }
1
2
3
隐藏导航栏最下面的黑线
- (void)hiddenNavLine { if ([self.navigationController.navigationBar respondsToSelector:@selector( setBackgroundImage:forBarMetrics:)]){ NSArray *list=self.navigationController.navigationBar.subviews; for (id obj in list) { if ([UIDevice currentDevice].systemVersion.floatValue >= 10.0) { UIView *view = (UIView*)obj; for (id obj2 in view.subviews) { if ([obj2 isKindOfClass:[UIImageView class]]) { UIImageView *image = (UIImageView*)obj2; image.hidden = YES; } } } } } }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
去除自带的searchBar的背景View
- (void)removeSearchBarBackGroundView { for(int i = 0 ;i < _searchBar.subviews.count;i++){ UIView * backView = _searchBar.subviews[i]; if ([backView isKindOfClass:NSClassFromString(@"UISearchBarBackground")] == YES) { [backView removeFromSuperview]; [_searchBar setBackgroundColor:[UIColor clearColor]]; break; } else { NSArray * arr = _searchBar.subviews[i].subviews; for(int j = 0;j < arr.count; j++){ UIView * barView = arr[i]; if ([barView isKindOfClass:NSClassFromString(@"UISearchBarBackground")] == YES) { [barView removeFromSuperview]; [_searchBar setBackgroundColor:[UIColor clearColor]]; break; } } } } }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
标签栏的背景图显示错乱问题解决办法:
//将图片如下设置 [[UIImage imageNamed:@"me@2x.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]
1
2
网络请求设置超时请求(基于AFNetworking3.0封装的GET,POST请求用方法)
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager]; [manager.requestSerializer willChangeValueForKey:@"timeoutInterval"]; manager.requestSerializer.timeoutInterval = 15.f; [manager.requestSerializer didChangeValueForKey:@"timeoutInterval"];
1
2
3
4
实用的获取图片的方法,防止内存溢出:
// 建议使用该方法: NSString *imagePath = [[NSBundle mainBundle] pathForResource:@"图片" ofType:@"png"]; UIImage *image = [[UIImage alloc] initWithContentsOfFile:imagePath]; // 不建议使用该方法: UIImage *image = [UIImage imageNamed:@"图片.png"];
1
2
3
4
5
6
iOS
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。