Skip to content

Instantly share code, notes, and snippets.

@Dellybro
Created November 22, 2016 22:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dellybro/a3e25ee2875c73860e28f971fa4519d6 to your computer and use it in GitHub Desktop.
Save Dellybro/a3e25ee2875c73860e28f971fa4519d6 to your computer and use it in GitHub Desktop.
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;
@end
@implementation CustomScripts
+ (UIImage *)scaleImage:(UIImage *)image scaledToSize:(CGSize)newSize {
//UIGraphicsBeginImageContext(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();
UIGraphicsEndImageContext();
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];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment