iPhone programming

UIScreen and scale

I was dealing with handling retina display in a project. According to the programming guide, I should change whether the screen is retina display or not by checking:


[[UIScreen mainScreen] scale]

that if scale is 2.0 it is retina display, if it is 1.0 it is normal display.

According to the document:
http://developer.apple.com/iphone/library/documentation/UIKit/Reference/...

It should be available after OS 4.0. So I assume that:


[UIScreen respondToSelector:@selector(scale)]

Clear location service object in resign active

Since iOS 4.0, I am aware freeing unnecessary object when the application is in inactive state so that the app can free up as much memory as possible. So in one of me location based app, I try to free the location service object when it is inactive:


- (void)applicationWillResignActive:(UIApplication *)application {
self.locationService = nil;
....
/*

UILabel align to top

UILabel will always align to the middle of the size of the control. So if you want to align to the top of margin, you have to set the height of the control exact the same to the height that need to show the text:

UILabel *l2; // l2 is the label that we are working
// find the new height
CGRect l2Rect = [l2 textRectForBounds:l2.bounds limitedToNumberOfLines:999];
// reset the height
CGRect f = l2.frame;
f.size.height = l2Rect.size.height;
l2.frame = f;

Syndicate content