iPhone SDK Tips & Tricks
float x = 1.23;
NSLog(@"%g", x); //1.23
NSLog(@"%f", x); //1.23000000
Rate this app
iPhone SDK Tips & Tricks
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?id=374892313&onlyLatestVersion=false&type=Purple+Software"]];
Replace id with the application ID from itunesconnect.
Labels:
iphone SDK,
rate
Get User Currency Code and Symbol
iPhone SDK Tips & Tricks
NSString *currencyCode = [[NSLocale currentLocale] objectForKey: NSLocaleCurrencyCode];
NSString *currencySymbol = [[NSLocale currentLocale] objectForKey: NSLocaleCurrencySymbol];
Labels:
code,
currency,
iphone SDK,
symbol
Number of days in current month
iPhone SDK Tips & Tricks
NSDate *today = [NSDate date]; //Get a date object for today's date
NSCalendar *c = [NSCalendar currentCalendar];
NSRange days = [c rangeOfUnit:NSDayCalendarUnit
inUnit:NSMonthCalendarUnit
forDate:today];
Labels:
date formatter,
day,
iphone SDK,
month,
number
Resize UIImage
iPhone SDK Tips & Tricks
-(UIImage *)resizeImage:(UIImage *)image {
CGImageRef imageRef = [image CGImage];
CGImageAlphaInfo alphaInfo = CGImageGetAlphaInfo(imageRef);
CGColorSpaceRef colorSpaceInfo = CGColorSpaceCreateDeviceRGB();
if (alphaInfo == kCGImageAlphaNone)
alphaInfo = kCGImageAlphaNoneSkipLast;
int width, height;
width = 200;
height = 200;
CGContextRef bitmap;
if (image.imageOrientation == UIImageOrientationUp | image.imageOrientation == UIImageOrientationDown) {
bitmap = CGBitmapContextCreate(NULL, width, height, CGImageGetBitsPerComponent(imageRef), CGImageGetBytesPerRow(imageRef), colorSpaceInfo, alphaInfo);
} else {
bitmap = CGBitmapContextCreate(NULL, height, width, CGImageGetBitsPerComponent(imageRef), CGImageGetBytesPerRow(imageRef), colorSpaceInfo, alphaInfo);
}
if (image.imageOrientation == UIImageOrientationLeft) {
NSLog(@"image orientation left");
CGContextRotateCTM (bitmap, radians(90));
CGContextTranslateCTM (bitmap, 0, -height);
} else if (image.imageOrientation == UIImageOrientationRight) {
NSLog(@"image orientation right");
CGContextRotateCTM (bitmap, radians(-90));
CGContextTranslateCTM (bitmap, -width, 0);
} else if (image.imageOrientation == UIImageOrientationUp) {
NSLog(@"image orientation up");
} else if (image.imageOrientation == UIImageOrientationDown) {
NSLog(@"image orientation down");
CGContextTranslateCTM (bitmap, width,height);
CGContextRotateCTM (bitmap, radians(-180.));
}
CGContextDrawImage(bitmap, CGRectMake(0, 0, width, height), imageRef);
CGImageRef ref = CGBitmapContextCreateImage(bitmap);
UIImage *result = [UIImage imageWithCGImage:ref];
CGContextRelease(bitmap);
CGImageRelease(ref);
return result;
}
-(UIImage *)resizeImage:(UIImage *)image {
CGImageRef imageRef = [image CGImage];
CGImageAlphaInfo alphaInfo = CGImageGetAlphaInfo(imageRef);
CGColorSpaceRef colorSpaceInfo = CGColorSpaceCreateDeviceRGB();
if (alphaInfo == kCGImageAlphaNone)
alphaInfo = kCGImageAlphaNoneSkipLast;
int width, height;
width = 200;
height = 200;
CGContextRef bitmap;
if (image.imageOrientation == UIImageOrientationUp | image.imageOrientation == UIImageOrientationDown) {
bitmap = CGBitmapContextCreate(NULL, width, height, CGImageGetBitsPerComponent(imageRef), CGImageGetBytesPerRow(imageRef), colorSpaceInfo, alphaInfo);
} else {
bitmap = CGBitmapContextCreate(NULL, height, width, CGImageGetBitsPerComponent(imageRef), CGImageGetBytesPerRow(imageRef), colorSpaceInfo, alphaInfo);
}
if (image.imageOrientation == UIImageOrientationLeft) {
NSLog(@"image orientation left");
CGContextRotateCTM (bitmap, radians(90));
CGContextTranslateCTM (bitmap, 0, -height);
} else if (image.imageOrientation == UIImageOrientationRight) {
NSLog(@"image orientation right");
CGContextRotateCTM (bitmap, radians(-90));
CGContextTranslateCTM (bitmap, -width, 0);
} else if (image.imageOrientation == UIImageOrientationUp) {
NSLog(@"image orientation up");
} else if (image.imageOrientation == UIImageOrientationDown) {
NSLog(@"image orientation down");
CGContextTranslateCTM (bitmap, width,height);
CGContextRotateCTM (bitmap, radians(-180.));
}
CGContextDrawImage(bitmap, CGRectMake(0, 0, width, height), imageRef);
CGImageRef ref = CGBitmapContextCreateImage(bitmap);
UIImage *result = [UIImage imageWithCGImage:ref];
CGContextRelease(bitmap);
CGImageRelease(ref);
return result;
}
Labels:
dimention,
iphone SDK,
resize image
NSDateFormatter
iPhone SDK Tips & Tricks
NSDateFormatter *dateFormat = [[[NSDateFormatter alloc] init] autorelease];
[dateFormat setDateFormat:@"dd MMM yyyy"];
NSLog(@"%@", [dateFormat stringFromDate:[NSDate date]]);
x number
xx two digit number
xxx abbreviated name
xxxx full name
a AM/PM
A millisecond of day
c day of week (c,cc,ccc,cccc)
d day of month
e day of week (e,EEE,EEEE)
F week of month
g julian day (since 1/1/4713 BC)
G era designator (G=GGG,GGGG)
h hour (1-12, zero padded)
H hour (0-23, zero padded)
L month of year (L,LL,LLL,LLLL)
m minute of hour (0-59, zero padded)
M month of year (M,MM,MMM,MMMM)
Q quarter of year (Q,QQ,QQQ,QQQQ)
s seconds of minute (0-59, zero padded)
S fraction of second
u zero padded year
v general timezone (v=vvv,vvvv)
w week of year (0-53, zero padded)
y year (y,yy,yyyy)
z specific timezone (z=zzz,zzzz)
Z timezone offset +0000
sql y-M-d H:m:s
rss [E, ]d MMM y[y] H:m:s Z|z[zzz]
Labels:
date formatter,
dateformat,
iphone SDK
Subscribe to:
Posts (Atom)