在调用系统相机时,"cancel" 改为"取消",调用系统相册时,"photos" 改为 "相机",方法如下:
1.在 info.plist 添加 Localized resources can be mixed 并设值为YES
表示是否允许应用程序获取框架库内语言。
2.在info.plist 中添加或修改 Localization native development region 选择 china
NSString *methodString = [NSString stringWithFormat:@"push%@Controller",itemModel.image];
NSAssert(methodString, @"未找到对应methodKey对应handle方法");
if (methodString) {
SEL selector = NSSelectorFromString(methodString);
IMP imp = [self.pushDelegate methodForSelector:selector];
void (*func)(id, SEL) = (void *)imp;
func(self.pushDelegate , selector);
}
IQKeyboardManager
- (void)setKeyboardManager{
IQKeyboardManager *keyboardManager = [IQKeyboardManager sharedManager]; // 获取类库的单例变量
keyboardManager.enable = YES; // 控制整个功能是否启用
keyboardManager.shouldResignOnTouchOutside = YES; // 控制点击背景是否收起键盘
keyboardManager.shouldToolbarUsesTextFieldTintColor = YES; // 控制键盘上的工具条文字颜色是否用户自定义
keyboardManager.toolbarManageBehaviour = IQAutoToolbarBySubviews; // 有多个输入框时,可以通过点击Toolbar 上的“前一个”“后一个”按钮来实现移动到不同的输入框
keyboardManager.enableAutoToolbar = YES; // 控制是否显示键盘上的工具条
keyboardManager.placeholderFont = [UIFont boldSystemFontOfSize:17]; // 设置占位文字的字体
keyboardManager.keyboardDistanceFromTextField = 10.0f; // 输入框距离键盘的距离
}
3 AFNetworking JSON数据
AFHTTPSessionManager *manger = [AFHTTPSessionManager manager];
//请求post json数据
manger.requestSerializer = [AFJSONRequestSerializer serializer];
[manger.requestSerializer setValue:@"application/json; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
4.优雅的隐藏导航栏
// 将要显示控制器
#pragma mark - UINavigationControllerDelegate
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
// 判断要显示的控制器是否是自己
BOOL isSelf = [viewController isKindOfClass:[self class]];
[self.navigationController setNavigationBarHidden:isSelf animated:YES];
}
获取当前控制器
- (UIViewController*)topViewController {
return [self topViewControllerWithRootViewController:[UIApplication sharedApplication].keyWindow.rootViewController];
}
- (UIViewController*)topViewControllerWithRootViewController:(UIViewController*)rootViewController {
if ([rootViewController isKindOfClass:[UITabBarController class]]) {
UITabBarController *tabBarController = (UITabBarController *)rootViewController;
return [self topViewControllerWithRootViewController:tabBarController.selectedViewController];
} else if ([rootViewController isKindOfClass:[UINavigationController class]]) {
UINavigationController* navigationController = (UINavigationController*)rootViewController;
return [self topViewControllerWithRootViewController:navigationController.visibleViewController];
} else if (rootViewController.presentedViewController) {
UIViewController* presentedViewController = rootViewController.presentedViewController;
return [self topViewControllerWithRootViewController:presentedViewController];
} else {
return rootViewController;
}
}
更改导航栏的返回按钮图标
///更改返回的颜色
[self.navigationController.navigationBar setBackIndicatorImage:[UIImage imageNamed:@"back.png"]];
[self.navigationController.navigationBar setBackIndicatorTransitionMaskImage:[UIImage imageNamed:@"back.png"]];
self.navigationController.navigationBar.tintColor= [UIColor whiteColor];
录音错误 Couldn't create a new audio file object
产生原因是: 没先创建子文件夹
/**
* 语音文件存储路径
*
* @return 路径
*/
func recordPath() -> String {
let documentPath : String = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first!
let filePath: String = documentPath.appending("/WXGsoundFile.war")
if !FileManager.default.fileExists(atPath: filePath) {
FileManager.default.createFile(atPath: filePath, contents: nil, attributes: nil)
}
// let warFilePath : String = filePath.appending("myRecord.war")
return filePath
}
获取相册照片 有heic格式的转换
//HEIC转换成jpg
CIImage *ciImage = [CIImage imageWithData:imageData];
CIContext *context = [CIContext context];
NSData *jpgData = [context JPEGRepresentationOfImage:ciImage colorSpace:ciImage.colorSpace options:@{}];
if (downloadFinined && imageData) {
if (completion) {
completion(jpgData,info,NO);
}
}
统计项目总行数
1.打开终端
2.cd 到工程目录下
3.输入命令
find . -name "*.m" -or -name "*.h" -or -name "*.xib" -or -name "*.c" |xargs wc -l
4.运行完打印出总行数(注释也统计在代码量之内)
5.grep -v "^$"
是去掉空行
find . -name "*.m" -or -name "*.h" -or -name "*.xib" -or -name "*.c" |xargs grep -v "^$"|wc -l
十进制与三十二进制互转
//十进制转换成三十二进制
+ (NSString *)ToHex:(long long)convert{
NSString * ruleValue;
NSString * string = @"";
long long temp;
do {
temp = convert%32;
convert = convert/32;
switch (temp){
case 10:ruleValue =@"A";break;
case 11:ruleValue =@"B";break;
case 12:ruleValue =@"C";break;
case 13:ruleValue =@"D";break;
case 14:ruleValue =@"E";break;
case 15:ruleValue =@"F";break;
case 16:ruleValue =@"G";break;
case 17:ruleValue =@"H";break;
case 18:ruleValue =@"I";break;
case 19:ruleValue =@"J";break;
case 20:ruleValue =@"K";break;
case 21:ruleValue =@"L";break;
case 22:ruleValue =@"M";break;
case 23:ruleValue =@"N";break;
case 24:ruleValue =@"O";break;
case 25:ruleValue =@"P";break;
case 26:ruleValue =@"Q";break;
case 27:ruleValue =@"R";break;
case 28:ruleValue =@"S";break;
case 29:ruleValue =@"T";break;
case 30:ruleValue =@"U";break;
case 31:ruleValue =@"V";
break;
default:
ruleValue = [NSString stringWithFormat:@"%lld",temp];
}
string = [ruleValue stringByAppendingString:string];
} while (convert != 0 );
return string.lowercaseString;
}
- (NSString *)dataDecoding{
return [NSString stringWithFormat:@"%lu",strtoul(self.UTF8String, 0, 32)];
}