初学ios的一些笔记
1。软键盘点击done后消失以及点击next后跳转到下一个textfield
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
if(textField == name1)
{
[name2becomeFirstResponder];
}
return YES;
}
2。数据永久化储存之NSUserDefaults用法
[[NSUserDefaults standardUserDefaults] setObject:@"hahaah" forKey:@"sam"];
[[NSUserDefaults standardUserDefaults] synchronize];
NSString *value = [[NSUserDefaultsstandardUserDefaults]objectForKey:@"sam"];
NSLog(@"value = %@",value);
3.使用文字的button
btn = [UIButtonbuttonWithType:UIButtonTypeRoundedRect];
btn.frame =CGRectMake(0,0,100,40);
[btnsetTitle:@"btn_off"forState:UIControlStateNormal];
[btnsetTitle:@"btn_on"forState:UIControlStateHighlighted];
[btnaddTarget:selfaction:@selector(onbuttonclick)forControlEvents:UIControlEventTouchUpInside];
4.返回int类型的当前时间和使用int类时间构造date
/获取系统时间
NSTimeInterval time = [[NSDatedate]timeIntervalSince1970];
NSLog(@"time = %d",(int)time);
NSDate *da = [NSDatedateWithTimeIntervalSince1970:(int)time];
NSDateFormatter* formatter = [[NSDateFormatteralloc]init];
[formatter setDateFormat:@"yyyy-MM-dd HH:MM:SS"];
NSString* str = [formatter stringFromDate:da];
NSLog(str);
5。拉伸图片,类似android的.9.png
-(UIImage *)stretchableImageWithLeftCapWidth:(NSInteger)leftCapWidth topCapHeight:(NSInteger)topCapHeight;
注意5.0以后该接口就deprecated了,需要用另外一个接口,在ios开发文档里有说明
6 往模拟器中添加文件来帮助调试
打开“终端”,依次输入下面的两条命令:
defaults write com.apple.finder AppleShowAllFiles -bool true
KillAll Finder
可以在finder中显示隐藏文件夹
之后找到路径 /Users/<youruser>/Library/Application Support/iPhone Simulator/4.3.2/Applications/<yourappguid>/Documents往里面拷贝文件即可
如果要取消显示隐藏文件夹 依次输入
defaults write com.apple.finder AppleShowAllFiles -bool false
KillAll Finder
即可
7 xcode编译时报错找不到库文件原因
原因是当把刚添加的库文件移到framework分类时,在buildphase里库文件变红了,也就是找不到了,需要重新添加一遍
8.文件操作
NSFileManager *filemanager = [NSFileManager defaultManager];
NSString *document = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES)objectAtIndex:0];
NSData *data1 = [@"hellosam" dataUsingEncoding:NSUTF8StringEncoding];
[data1 writeToFile:[document stringByAppendingPathComponent:@"1.json"] atomically:YES];
[data1 writeToFile:[document stringByAppendingPathComponent:@"2.json"] atomically:YES];
[filemanager createDirectoryAtPath:[document stringByAppendingPathComponent:@"11"]withIntermediateDirectories:YES attributes:nil error:nil];
BOOL isdir = NO;
BOOL isExist = NO;
NSArray *array = [filemanager contentsOfDirectoryAtPath:document error:nil];
for(NSString *pathComponent in array)
{
NSString *path = [document stringByAppendingPathComponent:pathComponent];
isExist = [filemanager fileExistsAtPath:path isDirectory:&isdir];
NSLog(@"文件(夹)地址 = %@",path);
NSLog(@"是否存在 = %d, 是否是文件夹 = %d",isExist,isdir);
}
9.获取资源文件
NSString *filepath = [[[NSBundlemainBundle]bundlePath]stringByAppendingPathComponent:@"20120817_142428.3gp"];
10.loadview时报错
在loadview中加载UI时记得调用[super loadview];否则报错
11.ios无法加载资源文件
我在Resources资源文件下放了一个test.vsh得文件,运行后发现无论如何无法在程序内部获取到资源文件,查找原因发现是因为没有加载到应用里,解决方法是在target->build phases->copy bundle resources选项里将这个文件加上就行
12.ios输入import时无法正确提示头文件
一般情况下输入import 后会自动提示需要导入得头文件,但是我明明把文件加入工程了却弹不出来,后来发现是类文件放在了工程顶层目录导致。
也就是说假如我新建一个工程aaaaaa,那么会生成一个aaaaaa目录,里面有个同样叫aaaaaa得目录和一个aaaaaa.xcodeproj得文件,将类文件放入到aaaaaa->aaaaaa文件夹里面即可解决问题,资源文件似乎不受此限
13.ios全屏幕显示照片
很简单,在viewcontroller的init函数里使用
self.wantsFullScreenLayout =YES;即可,此时坐标0,0位于屏幕左上角,被状态栏覆盖,而状态栏成半透明
如果想隐藏状态栏,在任何地方调用
[[UIApplicationsharedApplication]setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];即可
14.icon图标取消高光
在xcode中打开 yourprojectname-info.plist ,在root项上添加Icon already includes gloss and bevel effects项,并将该项选为true,
15.使用NSUserDefaults时,最好使用[userdefault synchronize];使其立即生效
16.显示和隐藏所有文件夹
<p style="margin: 5px auto; padding-top: 0px; padding-bottom: 0px;"><span style="margin: 0px; padding: 0px;">显示Mac隐藏文件的命令:defaults write com.apple.finder AppleShowAllFiles YES</span></p><p style="margin: 5px auto; padding-top: 0px; padding-bottom: 0px;"><span style="margin: 0px; padding: 0px;">隐藏Mac隐藏文件的命令:defaults write com.apple.finder AppleShowAllFiles NO</span><br style="margin: 0px; padding: 0px;" /><br style="margin: 0px; padding: 0px;" />输完单击Enter键,退出终端,重新启动Finder就可以了<br style="margin: 0px; padding: 0px;" /><br style="margin: 0px; padding: 0px;" />重启Finder:鼠标单击窗口左上角的苹果标志-->强制退出-->Finder-->重新启动</p>
17.共享ios的document文件夹
Applicatio-Info.plist内加入一个新的属性UIFileSharingEnabled,然后值设置为true即可
18.获取毫秒级系统时间
struct timeval curtime;
gettimeofday(&curtime, nil);
long timeM = curtime.tv_sec +curtime.tv_usec/1000000;
NSLog(@"get time by c = %ld",timeM);
NSDate *date = [NSDatedateWithTimeIntervalSince1970:timeM];
19获取系统版本号
[[UIDevicecurrentDevice].systemVersionfloatValue]
20.设置程序每次从后台进入时重新启动
在 info-plist 里面找到 Application does not run in background 一项,勾选即可。
21.获取年月日时间和设置年月日时间
获取当前年月日时间
NSCalendar *calendar = [NSCalendarcurrentCalendar];
NSDateComponents *comps= [calendarcomponents:(NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit)fromDate:[NSDatedate]];
NSLog(@"year=%d,month=%d,day = %d",[compsyear],[comps month],[comps day]);
获取时间差
-(int)getDayDurationFromYear:(int)year month:(int)month day:(int)day
{
NSDateComponents *comp = [[NSDateComponentsalloc]init];
[comp setYear:year];
[comp setMonth:month];
[comp setDay:day];
NSCalendar *calendar = [NSCalendarcurrentCalendar];
NSDate *date = [calendar dateFromComponents:comp];
NSTimeInterval timeinminus = [[NSDatedate] timeIntervalSince1970] - [date timeIntervalSince1970];
int dayinterval = (timeinminus/60.0/60.0/24.0);
[comp release];
return dayinterval;
}
22.uilabel自动调整高度
///自动调整高度
UILabel *label = [[UILabelalloc] init];
label.frame = CGRectMake(0,120, 200, 20);
label.backgroundColor = [UIColorblueColor];
label.textColor = [UIColorwhiteColor];
label.text=@"sfuiwhifguiweuy2738y8f9hfihsiduhfui32y8yf89ef9g2089ysfhuishfuihuh23ufhuhifgsidgfygig2u3ifhiusgfisuufusgfui";
label.numberOfLines = 0;
[label sizeToFit];
[self.view addSubview:label];
初学ios的一些笔记相关推荐
- ios开发学习笔记--Core Motion
iOS开发学习笔记之CoreMotion-运动传感器 官网文档:CoreMotion Framework Reference 一. 简介 现在的苹果手机都基本有运动传感器,能够过获取到设备的加 ...
- IOS之学习笔记十五(协议和委托的使用)
1.协议和委托的使用 1).协议可以看下我的这篇博客 IOS之学习笔记十四(协议的定义和实现) https://blog.csdn.net/u011068702/article/details/809 ...
- iOS工程开发笔记二
iOS工程开发笔记<二> 在Xcode 4, 5的模板工程中可以看到Precompile Prefix Header,但是在Xcode 6被去除了. Xcode 6去掉Precompile ...
- IOS开发学习笔记-----UILabel 详解
IOS开发学习笔记-----UILabel 详解 01 //创建uilabel 02 UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMa ...
- IOS开发学习笔记(一)
概述: iOS是苹果开发的手持设备操作系统(iPhone,iPad,iPod touch,iPad mini). 基于UNIX,层次架构:核心操作系统层(Core OS)-> 核心服务层(Cor ...
- 献给初学iOS的小盆友们------微博app项目开发之一项目初始化
献给初学iOS的小盆友们--微博app项目开发之一 项目初始化 本人自学iOS也有七八个月了,不敢说学到很深入了,但也算入了门.此次微博app项目参考了传智播客培训教材,主要学习内容有架构思想,封装思 ...
- ios逆向入门笔记-HOOK-QQ登录
ios逆向入门笔记-HOOK-QQ登录 选择目标 砸壳 基本调试 Reveal+确定目标action及target 利用Logos 进行 hook 后续 选择目标 在经过之前的配置,这次有点小改动= ...
- 开源高仿印象笔记的iOS应用——朝夕笔记(Oncenote)
iOS-Oncenote 这是一款类似于印象笔记Evernote的生活类iOS应用--朝夕笔记 Oncenote.我希望能为更多的iOS开发者提供帮助与服务.当然App中还有不少bug和可扩展的 ...
- mqtt android简书,iOS MQTT协议笔记
前言 接到任务项目需要用MQTT来写消息推送,经过一段时间在网上查看资料后写下这篇文章,文章内容大都来自互联网,在文章最后也会贴出相关网址和Demo.写这文章主要目的是自己总结下经验做下笔记,以便日后 ...
最新文章
- 0409-0416的笔记
- mysql中数据表如何关联_mysql 如何导入/导出2个关联表中的数据
- 安装oracle11g后plsql访问,64位Oracle_11g_R2安装+32位Plsql成功登录连接
- Windows Server 2008远程桌面端口更改方法
- 博弈入门(思想)HDkiki‘s game;
- C#跨线程操作控件的线程安全方法
- 华为云classroom应用_华为任正非:将来所有应用都会长在云土地上,但现在还不是...
- git rebase原理(转)
- python通过get方法获取key对应的值
- 云原生开发平台的选择
- 【量化选基】每年初购买过去5年收益最好的沪深300指数增强,会超过混合基金吗?
- 团队管理的四大挑战——用人篇
- wlmedia播放器集成(4)— 实现视频播放
- excel poi 加背景图_使用POI在Excel中添加外部图片
- VB基础版版务处理_20050605
- ACM-ICPC之路
- 雨林木风Ghostxp sp3五周年纪念版(精品)
- 专业的直播系统开发,在线直播源码讲解
- 第13周项目1 (1)
- atmega8 例程:12864例程