iOS 笔记
来源:互联网 发布:淘宝买东西 编辑:程序博客网 时间:2024/05/16 09:28
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 = [dateformatstringFromDate:[NSDatedate]];
[dateformat release];
return currentTime;
}
5.设置navigationbar
[self.navigationController.navigationBarsetTitleTextAttributes:[NSDictionarydictionaryWithObjectsAndKeys:[UIColorwhiteColor],UITextAttributeTextColor, [UIColorcolorWithRed:0.0green:0.0 blue:0.0 alpha:0.0],UITextAttributeTextShadowColor,[UIFontsystemFontOfSize:17],UITextAttributeFont,nil]];
[self.navigationController.navigationBarsetBackgroundImage:[UIImageimageNamed:@"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 = [UIColorblackColor].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:UIKeyboardWillShowNotificationobject:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardShow:)
name:UIKeyboardDidShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillHide:)
name:UIKeyboardWillHideNotificationobject: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 = [cacPathArrayobjectAtIndex: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 = [NSFileManagerdefaultManager];
创建本地文件夹:[fileManager createDirectoryAtPath:namewithIntermediateDirectories:YESattributes:nilerror:nil];
创建本地文件: [fileManager createFileAtPath:namecontents:nilattributes:nil];
重命名:[fileManager moveItemAtPath:[[self.copysFileArrayobjectAtIndex:i] objectForKey:LCLFileURL]toPath:[NSStringstringWithFormat:@"%@%@",self.currentFolderPath,name]error:&error]
删除:[fileManager removeItemAtPath:[[self.copysFileArrayobjectAtIndex:i] objectForKey:LCLFileURL]error:nil];
14. scrollview 放大图片
- (UIView*)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
for (id viewin [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 = [[UIActionSheetalloc]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 ([NSJSONSerializationisValidJSONObject:self.addPeopleArrray]){
NSError *error;
// 创造一个json从Data,NSJSONWritingPrettyPrinted指定的JSON数据产的空白,使输出更具可读性。
NSData *jsonData = [NSJSONSerializationdataWithJSONObject:self.addPeopleArrrayoptions:NSJSONWritingPrettyPrintederror:&error];
str =[[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
NSLog(@"json data:%@",str);
}
- iOS笔记
- iOS笔记
- ios 笔记
- IOS笔记
- IOS笔记
- ios -笔记
- ios 笔记
- IOS笔记
- iOS 笔记
- IOS笔记
- ios 笔记
- IOS 笔记
- ios笔记
- iOS笔记
- iOS 笔记
- ios笔记
- ios 笔记
- iOS笔记
- 心里不高兴
- 串口学习
- 喜欢把自己静静地
- 稀疏性与L1范数
- VS2012 无法启动IIS Express Web服务器的解决方案
- iOS 笔记
- C# Datatable的使用方法
- 第六周 项目2 对象作为数据成员
- windows+android+cocos2d-x环境配置
- 新浪微博demo设计大概思路和方法
- ie6 兼容 fixed
- 添加第三方类库造成的linker command failed with exit code 1 (use -v to see invocation)的错误调试
- 轻松打造品牌轻应用:实时Web App开发框架Clouda
- linux 隔行打印或隔行删除