1.配置全局为中文,例如输入框弹出“全选”
打开 info.plist 将Localization native development region 设置为china ;选择project 点击 info 在 localizations 添加 Chinese(Simplified)
2.节约内存读取本地文件
NSMutableData *data = [NSMutableDatadataWithContentsOfFile:fileName options:NSDataReadingMappedIfSafeerror:&error];
3.调整图片大小
//调整图片大小
+(UIImage *)scaleImage:(UIImage *)image toScale:(float)scaleSize
{
UIGraphicsBeginImageContext(CGSizeMake(image.size.width*scaleSize,image.size.height*scaleSize));
[image drawInRect:CGRectMake(0, 0, image.size.width * scaleSize, image.size.height *scaleSize)];
UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return scaledImage;
}
或者:
UIImage *images = [imagefixOrientation];
NSData *imageData = UIImageJPEGRepresentation(images, 0.3);
4.获取当前时间
//获取当前时间根据自定义格式,例如yyyy-MM-dd HH:mm:ss
+(NSString*)getCurrentTimeWithTimaFormat:(NSString *)timeFormat{
NSDateFormatter *dateformat=[[NSDateFormatter alloc]init];
[dateformat setDateFormat:timeFormat];
NSString *currentTime = [dateformat stringFromDate:[NSDate date]];
[dateformat release];
return currentTime;
}
5.设置navigationbar
[self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],UITextAttributeTextColor, [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.0],UITextAttributeTextShadowColor,[UIFont systemFontOfSize:17],UITextAttributeFont,nil]];
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"lclNavbar_black.png"] forBarMetrics:UIBarMetricsDefault];
6.设置statusbar
[[UIApplication sharedApplication]setStatusBarStyle:UIStatusBarStyleLightContent];
将 View controller-based status barappearance 设为 NO
7.强制转换为arc : -fobjc-arc
8.设置边框阴影
self.lclImageViewHeadBack.layer.shadowColor = [UIColor blackColor].CGColor;
self.lclImageViewHeadBack.layer.shadowOffset = CGSizeMake(-1.0, 1.0);
self.lclImageViewHeadBack.layer.shadowOpacity = 0.8;
self.lclImageViewHeadBack.layer.shadowRadius = 2.0;
9.监听键盘通知
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardShow:)
name:UIKeyboardDidShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillHide:)
name:UIKeyboardWillHideNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardHide:)
name:UIKeyboardDidHideNotification object:nil];
10. 沙盒存储/缓存路径
//NSString*tempPath = NSTemporaryDirectory();
//NSArray*cacPathArray =NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);//library
//NSArray *cacPathArray =NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES); //Documents
NSArray *cacPathArray = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); //cache
NSString *fileDir = [cacPathArray objectAtIndex:0];
11. 截屏
+(NSData*)getScreenImageFromView:(UIView *)view{
UIGraphicsBeginImageContext(view.bounds.size);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image=UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData *imageData = UIImageJPEGRepresentation(image, 0.3);
return imageData;
}
12. GCD 线程
dispatch_queue_t downloadQueue = dispatch_queue_create("lcl downloader", NULL);
dispatch_async(downloadQueue, ^{
dispatch_async(dispatch_get_main_queue(), ^{
});
});
dispatch_release(downloadQueue); //won’t actually go away until queue is empty
13. 本地文件处理:复制 删除 重命名
NSFileManager*fileManager = [NSFileManager defaultManager];
创建本地文件夹:[fileManager createDirectoryAtPath:name withIntermediateDirectories:YES attributes:nil error:nil];
创建本地文件: [fileManager createFileAtPath:name contents:nil attributes:nil];
重命名:[fileManager moveItemAtPath:[[self.copysFileArray objectAtIndex:i] objectForKey:LCLFileURL] toPath:[NSString stringWithFormat:@"%@%@",self.currentFolderPath,name] error:&error]
删除:[fileManager removeItemAtPath:[[self.copysFileArray objectAtIndex:i] objectForKey:LCLFileURL] error:nil];
14. scrollview 放大图片
- (UIView*)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
for (id view in [scrollView subviews]) {
if ([view isKindOfClass:[UIImageView class]]) {
return view;
}
}
return nil;
}
15.多参数传值
- (IBAction)showLCLActionSheetOnView:(UIView *)view otherButtonTitles:(NSString *)otherButtonTitles, ... NS_REQUIRES_NIL_TERMINATION{
UIActionSheet * actionSheet = [[UIActionSheet alloc]init];
int i=0;
va_list args;
// scan for arguments afterotherButtonTitles.
va_start(args, otherButtonTitles);
// get rest of the objects until nil isfound
for (NSString *str = otherButtonTitles;str != nil; str = va_arg(args,NSString*)) {
[actionSheet addButtonWithTitle:str];
i++;
}
va_end(args);
[actionSheet addButtonWithTitle:@"取消"];
[actionSheet setCancelButtonIndex:i];
[actionSheet setDelegate:self];
actionSheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
[actionSheet showInView:view];
[actionSheet release];
}
16. JSON 字符串转data
NSData* plistData =[message dataUsingEncoding:NSUTF8StringEncoding];
17. itunes 传输文件到app
设置 Application supports iTunes filesharing 为 YES
18. openfire 插件编译
进入build路径:/Users/lcl/Documents/workspace/openfire_src/build
编译所有插件
ant plugin
编译指定插件
ant plugin-Dplugin=SamplePlugin
19. id 转为json 字符串
NSString *str = nil;
if ([NSJSONSerialization isValidJSONObject:self.addPeopleArrray]){
NSError *error;
// 创造一个json从Data,NSJSONWritingPrettyPrinted指定的JSON数据产的空白,使输出更具可读性。
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:self.addPeopleArrray options:NSJSONWritingPrettyPrinted error:&error];
str =[[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
NSLog(@"json data:%@",str);
}