Skip to content

Instantly share code, notes, and snippets.

Created November 22, 2016 22:55
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
CustomScript Files
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@interface CustomScripts : NSObject
+ (UIImage *)scaleImage:(UIImage *)image scaledToSize:(CGSize)newSize;
+ (void)addShadowToView:(UIView*)view options:(NSDictionary*)options;
+ (UIColor *)colorWithHexString:(NSString *)stringToConvert;
@implementation CustomScripts
+ (UIImage *)scaleImage:(UIImage *)image scaledToSize:(CGSize)newSize {
// In next line, pass 0.0 to use the current device's pixel scaling factor (and thus account for Retina resolution).
// Pass 1.0 to force exact pixel size.
UIGraphicsBeginImageContextWithOptions(newSize, NO, 0.0);
[image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
return newImage;
//Havent added any options yet, these are defaults right now
+ (void)addShadowToView:(UIView*)view options:(NSDictionary*)options{
view.layer.shadowRadius = 6.0f;
view.layer.shadowColor = [UIColor blackColor].CGColor;
view.layer.shadowOffset = CGSizeMake(3.0f, 4.0f);
view.layer.shadowOpacity = 0.6f;
view.layer.masksToBounds = NO;
//Send a hex string and have it convereted to Color!
+ (UIColor *)colorWithHexString:(NSString *)stringToConvert
NSString *noHashString = [stringToConvert stringByReplacingOccurrencesOfString:@"#" withString:@""]; // remove the #
NSScanner *scanner = [NSScanner scannerWithString:noHashString];
[scanner setCharactersToBeSkipped:[NSCharacterSet symbolCharacterSet]]; // remove + and $
unsigned hex;
if (![scanner scanHexInt:&hex]) return nil;
int r = (hex >> 16) & 0xFF;
int g = (hex >> 8) & 0xFF;
int b = (hex) & 0xFF;
return [UIColor colorWithRed:r / 255.0f green:g / 255.0f blue:b / 255.0f alpha:1.0f];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment