This helper class can take any uiview and return to you a uiimage that is basicly a screenshot of that view. Throw this into a category and you’re good to go.

+ (UIImage*)viewAsImage:(UIView*)view {
	UIImage *image = nil;
	UIGraphicsBeginImageContextWithOptions(view.bounds.size, NO, [UIScreen mainScreen].scale);
	[view.layer renderInContext:UIGraphicsGetCurrentContext()];
	image = UIGraphicsGetImageFromCurrentImageContext();
	return image;

Quick Guide to iOS 7 status bar customization.

  1. Ensure you set UIViewControllerBasedStatusBarAppearance to boolean YES in your plist.
  2. Ensure you set still set the default statusBar style in your plist, this will show during the splash screen.
  3. Override preferredStatusBarStyle providing your View Controller is not inside a UINavigationController.
  4. If your View Controller is inside a UINavigationController then preferredStatusBarStyle seems to be ignored completely. Instead the UINavigationController’s navigationBar’s barStyle is used. A dark barStyle makes the statusBar white, the default barStyle makes the statusBar text black.

Here’s a little script I wrote that lets you do search and replace with confirmation in bash. It uses find so it can look recursively through your files and uses vim to do the actual searching and replacing.

#Usage ./viSearchReplace <original> <new> <filename or directory>
if [ $# -ne 3 ]; then
        echo "Usage:    ./viSearchReplace <original> <new> <filename or directory>"
        exit 1
for i in `find $3 ! -type d ! -name . ! -name .. ! -name $0`; do
    vim -c '%s/'$1'/'$2'/gc' -c 'wq' $i
exit 0

GitHub Link

I commited some code to this awesome github repository: Colours-for-iOS
It returns [UIColor black] or [UIColor white] based on which one contrasts best with your current UIColor object.

Just throw the UIColor+Colours.h/m into your project and include the .h in any file in which you use UIColor. To use my new method, simply create a UIColor object and call it’s blackOrWhiteContrastingColor method. It returns a black or white UIColor object which you can then for example, use to change font/text color which is displayed over the original color object.

Sometimes, if you don’t want to deal with autolayout or it simply isn’t performing in the way you want, the solution to your problem may be to use a separate storyboard for each device. To do that, add this code to your AppDelegate.m and make sure you have the separate storyboard files that you need.

Call this method in your application:didFinishLaunchingWithOptions: with this command:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    [self initializeStoryBoardBasedOnScreenSize];


-(void)initializeStoryBoardBasedOnScreenSize {
    UIStoryboard *storyboard = nil;
    if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone)
    {    // The iOS device = iPhone or iPod Touch
        CGSize iOSDeviceScreenSize = [[UIScreen mainScreen] bounds].size;
        if (iOSDeviceScreenSize.height == 480)
        {   // iPhone 3GS, 4, and 4S and iPod Touch 3rd and 4th generation: 3.5 inch screen (diagonally measured)
            NSLog(@"Loading iphone 4 storyboard");
            // Instantiate a new storyboard object using the storyboard file named MainStoryboard_iPhone
            storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil];
        if (iOSDeviceScreenSize.height == 568)
        {   // iPhone 5 and iPod Touch 5th generation: 4 inch screen (diagonally measured)
            NSLog(@"Loading iphone 5 storyboard");
            // Instantiate a new storyboard object using the storyboard file named Storyboard_iPhone4
           storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone5" bundle:nil];
    } else if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad){
        // The iOS device = iPad
        NSLog(@"Loading ipad storyboard");
        // Instantiate a new storyboard object using the storyboard file named Storyboard_iPhone35
        storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPad" bundle:nil];
    // Instantiate the initial view controller object from the storyboard
    UIViewController *initialViewController = [storyboard instantiateInitialViewController];
    // Instantiate a UIWindow object and initialize it with the screen size of the iOS device
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Set the initial view controller to be the root view controller of the window object
    self.window.rootViewController  = initialViewController;
    // Set the window object to be the key window and show it
    [self.window makeKeyAndVisible];

Parallax effect
Parallax effect

In iOS 7, Apple introduced a Parallax effect to the app screen. There is an API available for you to add this effect to your apps. This code lets you add a parallax effect to your apps in iOS 7. I haven’t tested this myself, but it looks like it should work.

Let me know how it goes!

UIInterpolatingMotionEffect *interpolationHorizontal = [[UIInterpolatingMotionEffect alloc]initWithKeyPath:@"center.x" type:UIInterpolatingMotionEffectTypeTiltAlongHorizontalAxis];
interpolationHorizontal.minimumRelativeValue = @-10.0;
interpolationHorizontal.maximumRelativeValue = @10.0;

UIInterpolatingMotionEffect *interpolationVertical = [[UIInterpolatingMotionEffect alloc]initWithKeyPath:@"center.y" type:UIInterpolatingMotionEffectTypeTiltAlongVerticalAxis];
interpolationVertical.minimumRelativeValue = @-10.0;
interpolationVertical.maximumRelativeValue = @10.0;

[self.background addMotionEffect:interpolationHorizontal];
[self.background addMotionEffect:interpolationVertical];

This is a UIAlertView that has a button linking to this website. It implements the UIAlertView delegate on self.

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"About"
                                                    message:@"Application developed by Kevin Yavno\n\nVersion 1.0"
    [alert show];

This is the implementation of the UIAlertViewDelegate. It’s not the best practice to compare the button title to a hardcoded string, but it gets the job done in this simple app.

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
    NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
    if([title isEqualToString:@"Website"])
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString: @""]];

Here is an example of how to present iOS’s built in Tweet Compose View. This code simple allocs the view controller, then sets the initial text. After setting the completion handler using a closure (lambda function if you want to get technical) it then finally presents it overtop of our current view.

You need to link the Twitter.framework library with your source to use this code.

Continue reading