1.iphone之xx_Prefix.pch的作用和用法
2.iphone之发布版本的时候移除NSLog输出的方法
只需要将下列代码加入到pch文件中即可,
__OPTIMIZE__这个编译选项是发布版本才有的,所以在编译调试版本的时候可以看到Log,而发布版本则没有Log。
#ifndef __OPTIMIZE__
#define NSLog(...) NSLog(__VA_ARGS__)
#else
#define NSLog(...) {}
#endif
3.iphone之取消icon的高光状态
系统会默认会在图标上 自动加上半透明的高光半圆,如果我们不想要这个效果或者图标本身已经包含了这个高光效果,我们可以在项目配置里把系统的高光功能取消掉:xcode3.2x建的项目:
在info plist里加一个配置项,key为“Icon already includes gloss and bevel effects”, 类型为bool,然后打上钩就,这样系统就不会自动加高光;xcode4建的项目:
在项目target的summary标签页下找到App Icons项,在“Prerendered”打上钩![](http://luoyl.info/wp-content/uploads/2012/03/1.jpg)
此时在info.plist里会多出一个配置项" Icon already includes gloss effects":
![](http://luoyl.info/wp-content/uploads/2012/03/2.jpg)
再找到 “Icon files (iOS 5)”项目(如果有的话),展开, 把里面的“Icon already includes gloss effects”也设置成“YES”:
![](http://luoyl.info/wp-content/uploads/2012/03/3.jpg)
这样程序中的高光效果就取消了。
4.iphone之unichar和初始化
在iphone/mac开发中,unichar是两字节长的char,代表unicode的一个字符。但在xcode中,初始化unichar是个问题。如果像下面这样声明,会有warning"Multi-character character constant"。
unichar a = '国';
这是因为C语言中两个单引号只能用于char。可以采用直接写文字编码的方式来初始化。
unichar a = 0x0100;
如果有很多个unichar怎么办?一个个去查表太麻烦了。可以采取变通的方法:
unichar a[10];
NSString *aString = @"一二三四五六七八九十";
for (int i = 0; i < 10; i++)
a[i] = [aString characterAtIndex:i];
5.iphone之转向appstore中商品
NSString *str =@"itms-apps://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware? id=473898949";[[UIApplication sharedApplication] openURL:[NSURLURLWithString:str]];
把"id=3410863403"换成id=xxxx(自己程序的ID),即可。
6.iphone之iphone控件尺寸
![](http://www.idev101.com/code/User_Interface/sizes.png)
Element | Size (in points) |
Window (including status bar) | 320 x 480 pts |
Status Bar (How to hide the status bar) | 20 pts |
View inside window (visible status bar) | 320 x 460 |
Navigation Bar | 44 pts |
Nav Bar Image /Toolbar Image | up to 20 x 20 pts (transparent PNG) |
Tab Bar | 49 pts |
Tab Bar Icon | up to 30 x 30 pts (transparent PNGs) |
Text Field | 31 pts |
Height of a view inside a navigation bar | 416 pts |
Height of a view inside a tab bar | 411 pts |
Height of a view inside a navbar and a tab bar | 367 pts |
Portrait Keyboard height | 216 pts |
Landscape Keyboard height | 140 pts |
Points vs. Pixels
The iPhone 4 introduced a high resolution display with twice the pixels of previous iPhones. However you don't have to modify your code to support high-res displays; the coordinate system goes by points rather than pixels, and the dimensions in points of the screen and all UI elements remain the same.iOS 4 supports high resolution displays (like the iPhone 4 display) via the scale property on UIScreen, UIView, UIImage, and CALayer classes. If the object is displaying high-res content, its scale property is set to 2.0. Otherwise it defaults to 1.0.
All you need to do to support high-res displays is to provide @2x versions of the images in your project. See the checklist for updating to iOS4 or Apple documentation for Supporting High Resolution Screens for more info.
Adjusting Sizes
Click here to see how to adjust View Frames and Bounds.Additional References
- Apple Documentation: Points vs. Pixels
- Apple Documentation: UIBarButtonItem Class Reference says "Typically, the size of a toolbar and navigation bar image is 20 x 20 points."
- Apple Documentation: UITabBarItem Class Reference says "The size of an tab bar image is typically 30 x 30 points."
7.iPhone之发送附件邮件代码
- MFMailComposeViewController *picker = [[MFMailComposeViewControlleralloc] init];
- picker.mailComposeDelegate = self;
- [pickersetSubject:@"I have a pencil for you"];
- NSString*databasePathFromApp = [[[NSBundle mainBundle] resourcePath]stringByAppendingPathComponent:@"10.pdf"];
- NSData*fileData = [NSDatadataWithContentsOfFile:databasePathFromApp];
- [pickeraddAttachmentData:fileData mimeType:@"application/pdf"fileName:@"15.pdf"];
- [pickeraddAttachmentData:fileData mimeType:@"application/pdf"fileName:@"16.pdf"];
- UIImage*roboPic = [UIImage imageNamed:@"1.png"];
- NSData*imageData = UIImageJPEGRepresentation(roboPic, 1);
- [pickeraddAttachmentData:imageData mimeType:@"image/jpg"fileName:@"1.png"];
- NSString*emailBody = @"This is a cool image of a robot Ifound. Check it out!";
- [pickersetMessageBody:emailBody isHTML:YES];
- [selfpresentModalViewController:picker animated:YES];
- [pickerrelease];
8.iphone之自动休眠定时器
Phone OS试图省电的一个方法是使用自动休眠定时器。
如果在一定的时间内没有检测到触摸事件,系统最初会使屏幕变暗,并最终完全关闭屏幕。大多数开发者都应该让这个定时器打开,但是,游戏和不使用触摸输入的应用程序开发者可以禁用这个定时器,使屏幕在应用程序运行时不会变暗。
将共享的
如果在一定的时间内没有检测到触摸事件,系统最初会使屏幕变暗,并最终完全关闭屏幕。大多数开发者都应该让这个定时器打开,但是,游戏和不使用触摸输入的应用程序开发者可以禁用这个定时器,使屏幕在应用程序运行时不会变暗。
将共享的
UIApplication
对象的
idleTimerDisabled
属性设置为
YES
,就可以禁用自动休眠定时器。
9.iphone之广告转向
- NSString *iTunesLink =@"http://itunes.apple.com/us/app/id(产口id号)?mt=8";
- [[UIApplication sharedApplication] openURL:[NSURLURLWithString:iTunesLink]];
10.iphone之navigationItem 添加标题视图的方法
但是如果题目太长,后半部分就变成省略号了,那要实现自定义字体。代码如下:
2. GTMBase64base64编码解码
3. TouchXMLxml解析
4. SFHFKeychainUtils安全保存用户密码到keychain中
5. MBProgressHUD很棒的一个加载等待特效框架
6. ASIHTTPRequesthttp等相关协议封装
7. EGORefreshTableHeaderVie w下拉刷新代码
8. AsyncImageView异步加载图片并缓存代码
- UILabel *titleText =[[UILabel alloc] initWithFrame: CGRectMake(0, 0,200, 20)];
- titleText.backgroundColor =[UIColor clearColor];
- [titleText setFont:[UIFontsystemFontOfSize:15.0]];
- [titleText setText:@"设置navigationItem标题的字体大小"];
- self.navigationItem.titleView=titleText;//titleView
- [titleText release];
11.iphone之开源类库工具
几个常用的开源类库及下载地址:
1.
jsonjson编码解码
2. GTMBase64base64编码解码
3. TouchXMLxml解析
4. SFHFKeychainUtils安全保存用户密码到keychain中
5. MBProgressHUD很棒的一个加载等待特效框架
6. ASIHTTPRequesthttp等相关协议封装
7. EGORefreshTableHeaderVie
8. AsyncImageView异步加载图片并缓存代码