iphone开发小技巧汇总
1.iphone之xx_Prefix.pch的作用和用法
pch,系统编译每个.m文件前,都会先import这个文件。这样既节省了你手动添加import的时间,也有助于加速编译.
还有就是可以在这里面放入宏,在整个工程中都可以用。节省了时间
2.iphone之发布版本的时候移除NSLog输出的方法
#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”打上钩
此时在info.plist里会多出一个配置项" Icon already includes gloss effects":
再找到 “Icon files (iOS 5)”项目(如果有的话),展开, 把里面的“Icon already includes gloss effects”也设置成“YES”:
这样程序中的高光效果就取消了。
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控件尺寸
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之自动休眠定时器
如果在一定的时间内没有检测到触摸事件,系统最初会使屏幕变暗,并最终完全关闭屏幕。大多数开发者都应该让这个定时器打开,但是,游戏和不使用触摸输入的应用程序开发者可以禁用这个定时器,使屏幕在应用程序运行时不会变暗。
将共享的 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 添加标题视图的方法
- 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. EGORefreshTableHeaderView下拉刷新代码
8. AsyncImageView异步加载图片并缓存代码
iphone开发小技巧汇总相关推荐
- iphone开发小技巧汇总(1)
1.iphone之xx_Prefix.pch的作用和用法 Prefix.pch:扩展名.pch表示"pre-compiled-header",这是一个你工程要用到的来自于外部 ...
- oracle ebs form 计算 汇总公式,Oracle+EBS+Form开发小技巧汇总
oracle form开发的技巧 content Oracle EBS Form开发小技巧汇总 ..................................... 2 Form中Block的重 ...
- Android开发-小技巧汇总2
启动虚拟机时,在 launch options 窗口中 有个 wipe user data ,勾选它,将会让虚拟机 [恢复出厂设置] 2.[如果想让自己的应用程序有多个启动图标:] 为一个应用的 多个 ...
- iOS开发小技巧汇总
1.App名称的修改 许多个人开发者或许会有和我一样的经历,开发一个App途中会想到更合适的名字,这时候变会修改工程名以达到App名称改变的目的,其实你可以一步到位-- 在info.plist中添加一 ...
- iphone开发小技巧,转载
1.获取全局的Delegate对象,这样我们可以调用这个对象里的方法和变量... 1.获取全局的Delegate对象,这样我们可以调用这个对象里的方法和变量: [(MyAppDelegate*)[[U ...
- VC小技巧汇总之对话框技巧
这篇文章主要介绍了VC小技巧汇总之对话框技巧,非常实用!对于进行VC开发有一定的参考借鉴价值,需要的朋友可以参考下 本文搜集汇总了VC中关于对话框常用的一些技巧,对于进行VC开发由于一定的参考借鉴价值 ...
- 移动Web开发小技巧
移动Web开发小技巧 添加到主屏后的标题(IOS) name="apple-mobile-web-app-title" content="标题"> 启用 ...
- 27个iOS开发小技巧
<span style="word-wrap: normal; word-break: normal; line-height: 1.5em; font-size: 14px; out ...
- 日常安排php,PHP日常开发小技巧
PHP日常开发小技巧 导语:PHP语言中,如果你懂得一些开发技巧,那么对你学PHP,会有很大的帮助.下面的是百分网小编为大家整理的PHP日常开发小技巧,希望对你能有所帮助. PHP批量取得checkb ...
最新文章
- python第一周小测验_Python小测试
- mysql concat键值对_MySQL中concat函数
- Jquery中怎样判断是否有网络
- Cocos2dx源码记录(11) CCPrimtiveCommand,CCPrimetive
- Python学习——02-Python基础——【9-面向对象进阶】——isinstance(obj,cls)、反射等...
- LeetCode 533. 孤独像素 II
- 电脑怎么卸载软件干净_不要说你的电脑卸载很干净!分享两款卸载神器!
- Linux下安装mongodb详细过程
- 安装引导黑屏_电脑黑屏要怎么重装系统修复
- 开发你自己的XMPP 续 - Openfire 插件开发
- java基于springboot+vue学生考勤签到请假管理系统84y43
- java udp发16进制数据_如何通过接口强制发送UDP数据包?
- 场景法设计测试用例ATM机取款问题
- English Grammar(二)
- 对自己狠一点,开始写作吧
- Amendment Quotation function in CLCL Plugin
- KPM算法思想及实现
- 世界上还有人以“厕所”为姓,都知道是哪国人
- python中使用什么命令安装组件_在离线环境下安装python组件
- iOS开发关于block和局部变量和全局变量
热门文章
- logback日志(requestId(请求ID))(processId(进程ID))
- 什麼是除甲醛?甲醛有害嗎?
- Linux如何将Mysql数据库自动从一台服务器备份到另一台服务器
- 微信小程序反编译wxss文件缺失_小程序反编译
- 【java笔记】java中用于小数进位的BigDecimal.setScale方法
- Java setScale方法保留n位小数
- LeetCode题解:704.二分查找
- java 无法读取文件_java 读取文件,无法显示文件内容,如何解决? 谢谢。
- vuex是什么?怎么使用?哪种功能场景使用它?
- 怎么把动图放到word里_WORD中如何插入动态图片