iphone学习(原创+搜集)
来源:互联网 发布:神圣计划软件 编辑:程序博客网 时间:2024/05/22 13:51
网络上搜索,不断更新中…
1.断点处查看变量内容:
po objc:输出[objc descripton];
print (int)[objc retainCount]:输出[objc retainCount)。 注:print [objc retainCount]不行。
print (CGRect)[view frame]:输出view.frame。 注:print [view frame] 或 print (CGRect)view.frame 不行。
2.修改UIAlertView背景:
theAlert.layer.contents = (id)[UIImageObjc CGImage];
3.减少图片在程序的缓存,尤其大图片画在更小的范围内时。
代码
<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->- (UIImage *)rescaleImageToSize:(CGSize)size {
CGRect rect = CGRectMake(0.0,0.0, size.width, size.height);
UIGraphicsBeginImageContext(rect.size);
[self drawInRect:rect]; // scales image to rect
UIImage *resImage= UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return resImage;
}
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->- (UIImage *)rescaleImageToSize:(CGSize)size {
CGRect rect = CGRectMake(0.0,0.0, size.width, size.height);
UIGraphicsBeginImageContext(rect.size);
[self drawInRect:rect]; // scales image to rect
UIImage *resImage= UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return resImage;
}
4.使用不长时间cache的UIImage:
代码
<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->+ (UIImage *)myImageNamed:(NSString*)name{
name = [name substringToIndex:name.length-4];
NSString *path= [[NSBundle mainBundle] pathForResource:name ofType:@"png"];
return [UIImage imageWithContentsOfFile:path];
}
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->+ (UIImage *)myImageNamed:(NSString*)name{
name = [name substringToIndex:name.length-4];
NSString *path= [[NSBundle mainBundle] pathForResource:name ofType:@"png"];
return [UIImage imageWithContentsOfFile:path];
}
5.计算String的Label范围 :
代码
<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->CGSize calcLabelSize(NSString *string, UIFont*font, NSInteger lines,float lineWidth) {
float lineHeight= [@"Fake line" sizeWithFont: font ].height;// Calculate the height of one line.
if (string== nil ) {
return CGSizeMake(lineWidth, lineHeight);
}
NSMutableString *tmpString= [[NSMutableString alloc] init];
[tmpString setString:[string stringByReplacingOccurrencesOfString:@"<br />" withString:@"\n"]];
int numLines= [tmpString sizeWithFont: font constrainedToSize: CGSizeMake(lineWidth, lineHeight*1000.0f) lineBreakMode: UILineBreakModeTailTruncation ].height / lineHeight;// Get the total height, divide by the height of one line to get the # of lines.
[tmpString release];
if ( numLines> lines )
numLines = lines;// Set the number of lines to the maximum allowed if it goes over.
numLines +=1;//rena add
return CGSizeMake(lineWidth, (lineHeight*(float)numLines));// multiply the # of lines by the height of one line and return.
}
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->CGSize calcLabelSize(NSString *string, UIFont*font, NSInteger lines,float lineWidth) {
float lineHeight= [@"Fake line" sizeWithFont: font ].height;// Calculate the height of one line.
if (string== nil ) {
return CGSizeMake(lineWidth, lineHeight);
}
NSMutableString *tmpString= [[NSMutableString alloc] init];
[tmpString setString:[string stringByReplacingOccurrencesOfString:@"<br />" withString:@"\n"]];
int numLines= [tmpString sizeWithFont: font constrainedToSize: CGSizeMake(lineWidth, lineHeight*1000.0f) lineBreakMode: UILineBreakModeTailTruncation ].height / lineHeight;// Get the total height, divide by the height of one line to get the # of lines.
[tmpString release];
if ( numLines> lines )
numLines = lines;// Set the number of lines to the maximum allowed if it goes over.
numLines +=1;//rena add
return CGSizeMake(lineWidth, (lineHeight*(float)numLines));// multiply the # of lines by the height of one line and return.
}
6.NSData格式化:
该格式可以指定以下内容:
NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init];[outputFormatter setDateFormat:@"HH:mm 'on' EEEE MMMM d"];
NSString *newDateString = [outputFormatter stringFromDate:formatterDate];
01
G: 公元时代,例如AD公元
02
yy: 年的后2位
03
yyyy: 完整年
04
MM: 月,显示为1-12
05
MMM: 月,显示为英文月份简写,如 Jan
06
MMMM: 月,显示为英文月份全称,如 Janualy
07
dd: 日,2位数表示,如02
08
d: 日,1-2位显示,如 2
09
EEE: 简写星期几,如Sun
10
EEEE: 全写星期几,如Sunday
11
aa: 上下午,AM/PM
12
H: 时,24小时制,0-23
13
K:时,12小时制,0-11
14
m: 分,1-2位
15
mm: 分,2位
16
s: 秒,1-2位
17
ss: 秒,2位
18
S: 毫秒
7.宏定义
// 是否高清屏#define isRetina ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 960), [[UIScreen mainScreen] currentMode].size) : NO)// 是否iPad#define isPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)// 是否模拟器#define isSimulator (NSNotFound != [[[UIDevice currentDevice] model] rangeOfString:@"Simulator"].location)
- iphone学习(原创+搜集)
- iphone资料 各种网址搜集
- 我常用的iphone开发学习网站[原创]
- SQLite学习笔记(10)资料搜集
- FLV学习(一)网上资源搜集
- FLV学习(一)网上资源搜集
- 经典非原创,搜集网页常用Javascript
- Linux学习资源搜集
- python学习网站搜集
- 深度学习源码搜集
- 【深度学习】资料搜集
- NS2学习资料搜集
- jqgrid学习系列搜集
- 搜集的学习资料
- html5学习资料搜集
- Boost学习资源搜集
- 学习资源搜集
- UE4学习资料搜集
- 在CSS里什么是父元素和兄弟元素?老是提到父元素和兄弟元素?
- WWDC2010 Session206 介绍iPhone上的Blocks和Grand Central Dispatch (1)
- Linux Shell简介
- 迷宫问题
- WWDC2010 Session206 介绍iPhone上的Blocks和Grand Central Dispatch (2)
- iphone学习(原创+搜集)
- WWDC2010 Session211 使用Grad Central Dispatch简化iPhone开发
- 解决:对COM 组件的调用返回了错误 HRESULT E_FAIL
- 《objective-c 2.0 程序设计》学习笔记
- 让支持Block的app运行于iOS3.x
- 深入浅出 Android Service(1)
- 如何做1像素细边框的table?
- django的helloworld程序
- 在android应用中植入Admob广告赚钱