Coding, How-To

iOS: Getting Screen Size

To obtain the screen size based on the orientation and type of device, use this: screenWidth will return the width, and screenHeight, the height of your screen, even when your device is in the landscape orientation.

Coding

iOS: Random Number Generation

Use the arc4random function to generate random numbers in a range. Suppose you have to generate a random number from 0 to 99. Do: int randomNum0to99 = arc4random() % 100; Or: int randomNum0to99 = arc4random_uniform(100); Between the 2 codes, the latter is preferred because: arc4random_uniform() will return a uniformly distributed random number less than upper_bound.… Read More iOS: Random Number Generation

Coding, How-To

iOS: Remove Leading and Trailing Whitespaces in NSString Object

This tip is especially useful because users might not notice the extra whitespace characters at the start and end of their text when they type into your text fields. The following code snippet will allow you to do that in iOS: NSString *newString = [someString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; You may use [NSCharacterSet whitespaceCharacterSet] if you do… Read More iOS: Remove Leading and Trailing Whitespaces in NSString Object

Coding

iOS: Remove Status Bar

Sometimes you might like your status bar in your iOS app to be removed so that it’s more aesthetically pleasing. Try this snippet of code in your UIViewController classes: