1、图片拉伸
UIImage *img = [UIImage imageNamed:@"inputbox.png"]; UIImage *stretchedImage = [img stretchableImageWithLeftCapWidth:20.0f topCapHeight:10.0f];
2、键盘高度
ios5 以前中文键盘高度216.0f
ios5 以后中文键盘高度252.0f
3、emoji小图标
http://www.easyapns.com/iphone-emoji-alerts
4、使用ASI时,需要引入的一些framework
5、获取documents目录和资源
// NSString *cookiesPath = [[self applicationDocumentsDirectory] stringByAppendingString:@"/session.Cookies"]; - (NSString *)applicationDocumentsDirectory { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil; return basePath; }
获取资源: NSString *filePath = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"js"];
6、格式化时间
NSDate *date = [NSDate date]; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"MM-dd-yyyy HH:mm:ss"]; NSLog(@"%@ \n",[dateFormatter stringFromDate:date]);
7、区分设备是否是iPad
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { // iPad style UI } else { // iPhone and iPod touch style UI }
8、touches -> touchesPoint
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; CGPoint touchPoint = [touch locationInView:self]; [self handleTouchEvent:touchPoint touchType:Touch_Down_Event_Type]; }
9、获取 info.plist 文件中的值
NSBundle *mainBundle = [NSBundle mainBundle]; NSDictionary *infoDictionary = [mainBundle infoDictionary]; [header setObject:[infoDictionary objectForKey:@"CFBundleVersion"] forKey:@"version"];
10、NSNotificationCenter
NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter]; [notificationCenter addObserver:self selector:@selector(tableHeaderButtonClicked:) name:kTableHeaderButtonClicked object:nil]; [[NSNotificationCenter defaultCenter] postNotificationName:kTableHeaderButtonClicked object:nil userInfo:nil]; [[NSNotificationCenter defaultCenter] removeObserver:self name:kTableHeaderButtonClicked object:nil];
11、模拟器中程序文件位置
打开某个文件夹,快捷键 command + shift + g, 把下面的地址粘进去, Enter
~/Library/Application Support/iPhone Simulator
12、url encode
url = (NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)url, nil, nil, kCFStringEncodingUTF8);
13、在xcode4中使用NSZombieEnabled调试程序
http://stackoverflow.com/questions/2190227/how-do-i-setup-nszombieenabled-in-xcode-4
14、NSString编码转换(偶遇乱码问题)
NSStringEncoding enc = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000); NSString *encodingStr = [[NSString alloc] initWithData:request.responseData encoding:enc];
15、判断是否是simulator
#if TARGET_IPHONE_SIMULATOR // Simulator code #else // Device code #endif