Wednesday, June 25, 2014

Utility for ObjC



#import <Foundation/Foundation.h>
@interface Utility : NSObject

+(BOOL)isiPhone5;
+(void)addGradientToView : (UIView *)aView
        withStartingColor:(UIColor *)startColor
              endingColor:(UIColor *)endColor;


+(UIImage *)resizeImage:(UIImage *)aImage toSize:(CGSize)size;


@end



#import "Utility.h"

@implementation Utitlity

+(BOOL)isiPhone5 {
 
  BOOL result = NO;
 
  if([[UIScreen mainScreen] bounds].size.height == 568.0f) {
    result = YES;
    NSLog(@"iPhone 5");
  } else {
    NSLog(@"iPhone 4");
  }
 
  return result;
}


+(void)addGradientToView : (UIView *)aView withStartingColor:(UIColor *)startColor endingColor:(UIColor *)endColor {
 
  CAGradientLayer *gradient = [CAGradientLayer layer];
  gradient.frame  = aView.bounds;
  gradient.colors = [NSArray arrayWithObjects:(id)[startColor CGColor], (id)[endColor CGColor], nil];
  [aView.layer insertSublayer:gradient atIndex:0];
}


+(UIImage *)resizeImage:(UIImage *)aImage toSize:(CGSize)size {
 
  UIImage *resultImage = nil;
 
  UIGraphicsBeginImageContext(size);
  CGRect imageRect = CGRectMake(0.0, 0.0, size.width, size.height);
  [aImage drawInRect:imageRect];
  resultImage = UIGraphicsGetImageFromCurrentImageContext();
  UIGraphicsEndImageContext();
 
  return resultImage;
}


@end



No comments: