本次公司OA开发中使用了一些小技巧
1、删除NSUserDefaults所有记录
//方法一NSString*appDomain = [[NSBundlemainBundle] bundleIdentifier];[[NSUserDefaultsstandardUserDefaults] removePersistentDomainForName:appDomain];//方法二- (void)resetDefaults{NSUserDefaults* defs = [NSUserDefaultsstandardUserDefaults];NSDictionary* dict = [defs dictionaryRepresentation];for(idkeyindict) { [defs removeObjectForKey:key]; } [defs synchronize];}
2、字符串按多个符号分割
NSString *str = @"abc,vfr.yyu";
NSCharacterSet *set = [NSCharacterSet characterSetWithCharactersInstring:@",."];
3iOS 获取汉字的拼音
+ (NSString*)transform:(NSString*)chinese{//将NSString装换成NSMutableString NSMutableString*pinyin = [chinese mutableCopy];//将汉字转换为拼音(带音标) CFStringTransform((__bridgeCFMutableStringRef)pinyin,NULL, kCFStringTransformMandarinLatin,NO);NSLog(@"%@", pinyin);//去掉拼音的音标 CFStringTransform((__bridgeCFMutableStringRef)pinyin,NULL, kCFStringTransformStripCombiningMarks,NO);NSLog(@"%@", pinyin);//返回最近结果 returnpinyin; }
4手动更改iOS状态栏的颜色
- (void)setStatusBarBackgroundColor:(UIColor*)color{UIView*statusBar = [[[UIApplicationsharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"];if([statusBar respondsToSelector:@selector(setBackgroundColor:)]) { statusBar.backgroundColor = color; }}
5判断当前ViewController是push还是present的方式显示的
NSArray*viewcontrollers=self.navigationController.viewControllers;if(viewcontrollers.count >1){if([viewcontrollers objectAtIndex:viewcontrollers.count -1] ==self) {//push方式[self.navigationController popViewControllerAnimated:YES]; }}else{//present方式[selfdismissViewControllerAnimated:YEScompletion:nil];}
作者:iOS_小松哥
链接:https://www.jianshu.com/p/4523eafb4cd4
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
网友评论