function isIE(){ //判断是否是ie if (window.navigator.userAgent.toString().toLowerCase().indexOf("msie") >=1) return true; else return false; } if(!isIE()){ //firefox innerText define HTMLElement.prototype.__defineGetter__( "innerText", function(){ var anyString = ""; var childS = this.childNodes; for(var i=0; i <childS.length; i++) { if(childS[i].nodeType==1) anyString += childS[i].tagName=="BR" ? '\n' : childS[i].innerText; else if(childS[i].nodeType==3) anyString += childS[i].nodeValue; } return anyString; } ); HTMLElement.prototype.__defineSetter__( "innerText", function(sText){ this.textContent=sText; } ); }
1. int
输出格式符:%i, %d, %o %x,2. float
输出格式符:%f, %e, %g
3. double
输出格式符:%f, %e, %g
输出格式符:%c
限定符:
1. long
long int: %li
long double: %Lf
形成long int通过在数字后面加L.
long int number = 123324123234123L;
2. long long
long long int: %lli
3. short
short int: %hi
4. unsigned
5. signed
它们各自所占的字节数
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSLog(@"The size of an int is: %d bytes.",sizeof(int));
NSLog(@"The size of a short int is: %d bytes.",sizeof(short int));
NSLog(@"The size of a long int is: %d bytes.",sizeof(long int));
NSLog(@"The size of a char is: %d bytes.",sizeof(char));
NSLog(@"The size of a float is: %d bytes.",sizeof(float));
NSLog(@"The size of a double is: %d bytes.",sizeof(double));
NSLog(@"The size of a bool is: %d bytes.",sizeof(bool));
[pool drain];
return 0;
}
2011-08-21 09:29:16.475 sizeofTest[860:903] The size of an int is: 4 bytes.
2011-08-21 09:29:16.478 sizeofTest[860:903] The size of a short int is: 2 bytes.
2011-08-21 09:29:16.478 sizeofTest[860:903] The size of a long int is: 8 bytes.
2011-08-21 09:29:16.479 sizeofTest[860:903] The size of a char is: 1 bytes.
2011-08-21 09:29:16.479 sizeofTest[860:903] The size of a float is: 4 bytes.
2011-08-21 09:29:16.479 sizeofTest[860:903] The size of a double is: 8 bytes.
2011-08-21 09:29:16.480 sizeofTest[860:903] The size of a bool is: 1 bytes.
logout
转自:http://www.cnblogs.com/getsun/archive/2011/08/21/2147618.html
头文件:
#import <UIKit/UIKit.h> #include <math.h> static inline double radians(double degrees) { return degrees * M_PI / 180; } #define FontSize 20.0f @interface DrawScreen : UIView { } - (void)drawTextByString:(NSString *)drawText thePoisition:(CGPoint)point; - (void)drawPicByImage:(UIImage *)theImage theRect:(CGRect)rect; - (void)drawTextByQuartz:(CGContextRef)context theText:(const char *)drawtext thePoisition:(CGPoint)point rotateAngle:(float)angle; - (void)drawPicByQuartz:(CGContextRef)context thePic:(UIImage *)theImage theLocation:(CGRect)rect; @end
实现文件:
#import "DrawScreen.h" @implementation DrawScreen - (id)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { self.backgroundColor = [UIColor blackColor]; } return self; } - (void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetFillColorWithColor(context, [UIColor greenColor].CGColor); //方式一:用NSString的方式画字,用UIImage的方式画图片,坐标原点在左上角 NSString *textOne = [NSString stringWithFormat:@"iPad"]; NSString *textTwo = [NSString stringWithFormat:@"iPhone"]; [self drawTextByString:textOne thePoisition:CGPointMake(50.0f, 260.0f)]; [self drawTextByString:textTwo thePoisition:CGPointMake(250.0f, 260.0f)]; UIImage *flagOne = [UIImage imageNamed:@"flag.png"]; [self drawPicByImage:flagOne theRect:CGRectMake(50.0f, 200.0f, 45.0f, 45.0f)]; [self drawPicByImage:flagOne theRect:CGRectMake(250.0f, 200.0f, 45.0f, 45.0f)]; //方式二:用Quartz2D的方式画字和图片,坐标原点移动到左下角 CGContextTranslateCTM(context, 0, self.bounds.size.height); CGContextScaleCTM(context, 1, -1); UIImage *flagTwo = [UIImage imageNamed:@"location.png"]; [self drawTextByQuartz:context theText:"Apple" thePoisition:CGPointMake(160.0f, 200.0f) rotateAngle:45.0f]; [self drawTextByQuartz:context theText:"iPod" thePoisition:CGPointMake(50.0f, 100.0f) rotateAngle:45.0f]; [self drawTextByQuartz:context theText:"iMac" thePoisition:CGPointMake(250.0f, 100.0f) rotateAngle:45.0f]; [self drawPicByQuartz:context thePic:flagTwo theLocation:CGRectMake(160.0f, 230.0f, 50.0f, 50.0f)]; [self drawPicByQuartz:context thePic:flagTwo theLocation:CGRectMake(50.0f, 130.0f, 50.0f, 50.0f)]; [self drawPicByQuartz:context thePic:flagTwo theLocation:CGRectMake(250.0f, 130.0f, 50.0f, 50.0f)]; } - (void)dealloc { [super dealloc]; } - (void)drawTextByString:(NSString *)drawText thePoisition:(CGPoint)point { //方式一 [drawText drawAtPoint:point withFont:[UIFont systemFontOfSize:FontSize]]; } - (void)drawPicByImage:(UIImage *)theImage theRect:(CGRect)rect { //方式一 [theImage drawInRect:rect]; } - (void)drawTextByQuartz:(CGContextRef)context theText:(const char *)drawtext thePoisition:(CGPoint)point rotateAngle:(float)angle { //方式二 CGContextSelectFont(context, "Helvetica", FontSize, kCGEncodingMacRoman); CGContextSetTextDrawingMode(context, kCGTextFill); CGAffineTransform myTextTransform = CGAffineTransformMakeRotation(radians(angle)); CGContextSetTextMatrix (context, myTextTransform); CGContextShowTextAtPoint(context, point.x, point.y, drawtext, strlen(drawtext)); } - (void)drawPicByQuartz:(CGContextRef)context thePic:(UIImage *)theImage theLocation:(CGRect)rect { //方式二 CGContextDrawImage(context, rect, theImage.CGImage); } @end
示例图: