Skip to content

Instantly share code, notes, and snippets.

View ArtSabintsev's full-sized avatar
😎
Having fun!

Arthur Ariel Sabintsev ArtSabintsev

😎
Having fun!
View GitHub Profile
@ArtSabintsev
ArtSabintsev / CoreGraphicsGraident.m
Created May 30, 2012 14:01
Core Graphics Gradient (iOS 5 Compatible, ARC Compatible)
// Macros for the top and bottom colors of the gradient
#define kGradientTopColor {0.0f/255.0f, 0.0f/255.0f, 0.0f/255.0f, 1.0f}
#define kGradientBottomColor {209.0f/255.0f, 209.0f/255.0f, 209.0f/255.0f, 1.0f}
// Macro for the area that should be covered by the gradient
#define kGradientBounds self.bounds
// Customize your UIView (e.g., UIView, UILabel, UIButton, etc...) drawRect method
- (void)drawRect:(CGRect)rect
{
@ArtSabintsev
ArtSabintsev / DestroyWebview.m
Created January 24, 2013 21:53
How to properly remove an instance of UIWebView and avoid memory leaks
// Destroy UIWebView
- (void)destroyWebView
{
[self.webView loadHTMLString:@"" baseURL:nil];
[self.webView stopLoading];
[self.webView setDelegate:nil];
[self.webView removeFromSuperview];
[self setWebView:nil];
[[NSURLCache sharedURLCache] removeAllCachedResponses];
layout category tags
post
resource
html
css
javascript
resources
links

##specs

@implementation UIImage (WRExtensions)
#pragma mark -
#pragma mark Scale and crop image
- (UIImage*)imageByScalingAndCroppingForSize:(CGSize)targetSize
{
UIImage *sourceImage = self;
UIImage *newImage = nil;
CGSize imageSize = sourceImage.size;
@ArtSabintsev
ArtSabintsev / Native Base64 (Pre iOS7)
Created September 11, 2013 06:19
A category on NSString that exploits a set of CoreFoundation methods to create Base64 encoded strings. This is a simple solution that removes the need for external Base64 libraries in projects that targets apps that support iOS 2 - iOS 6. iOS 7 has a more concrete solution, but due to NDA, I cannot post it yet.
+ (NSString *)base64EncodeString:(NSString *)stringToEncode
{
CFHTTPMessageRef messageRef = CFHTTPMessageCreateEmpty(kCFAllocatorDefault, FALSE);
CFHTTPMessageAddAuthentication(messageRef, NULL, CFSTR("AS"), (__bridge CFStringRef)stringToEncode, kCFHTTPAuthenticationSchemeBasic, FALSE);
CFStringRef authStringRef = CFHTTPMessageCopyHeaderFieldValue(messageRef, CFSTR("Authorization"));
NSString *encodedString = [(__bridge NSString *)authStringRef substringFromIndex:10];
CFRelease(messageRef);
@ArtSabintsev
ArtSabintsev / Create iOS Icons.jsx
Last active December 24, 2015 22:19 — forked from twonjosh/Create iOS Icons.jsx
Create iOS App icons for iOS 4, 5, 6, 7, & 8
// Photoshop Script to Create iPhone Icons from iTunesArtwork
//
// WARNING!!! In the rare case that there are name collisions, this script will
// overwrite (delete perminently) files in the same folder in which the selected
// iTunesArtwork file is located. Therefore, to be safe, before running the
// script, it's best to make sure the selected iTuensArtwork file is the only
// file in its containing folder.
//
// Copyright (c) 2010 Matt Di Pasquale
// Added tweaks Copyright (c) 2012 by Josh Jones http://www.appsbynight.com
@ArtSabintsev
ArtSabintsev / Custom Pop-up with UIAlertView-style animation
Created November 4, 2013 18:25
I was searching for a way to perform an iOS-6 (and older) style UIAlertView animation pop up. I came across this code from http://stackoverflow.com/a/3004247/814861. I've copied it over here for my own records (with very slight readability modifications).
- (void)popView:(UIView *)viewToPop
{
CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
NSValue *scale1Value = [NSValue valueWithCATransform3D:CATransform3DMakeScale(0.5f, 0.5f, 1.0f)];
NSValue *scale2Value = [NSValue valueWithCATransform3D:CATransform3DMakeScale(1.2f, 1.2f, 1.0f)];
NSValue *scale3Value = [NSValue valueWithCATransform3D:CATransform3DMakeScale(0.9f, 0.9f, 1.0f)];
NSValue *scale4Value = [NSValue valueWithCATransform3D:CATransform3DMakeScale(1.0f, 1.0f, 1.0f)];
NSArray *frameValues = [NSArray arrayWithObjects:scale1Value, scale2Value, scale3Value, scale4Value, nil];
[animation setValues:frameValues];
@ArtSabintsev
ArtSabintsev / UIImage+ResizeImage.h
Created November 20, 2013 01:08
This UIImage category adds one class method that enables you to resize an image, in case you have an asset that is too large.
#import <UIKit/UIKit.h>
@interface UIImage (ResizeImage)
+ (UIImage *)convertImage:(UIImage *)image toSize:(CGSize)size;
@end
@ArtSabintsev
ArtSabintsev / gist:8290404
Created January 6, 2014 21:49
How to delete a Git Submodule
Delete the relevant section from the .gitmodules file.
Stage the .gitmodules changes git add .gitmodules
Delete the relevant section from .git/config.
Run git rm --cached path_to_submodule (no trailing slash).
Run rm -rf .git/modules/path_to_submodule
Commit git commit -m "Removed submodule <name>"
Delete the now untracked submodule files
rm -rf path_to_submodule
@ArtSabintsev
ArtSabintsev / viewFromBarButtonItem.m
Last active August 31, 2018 16:55
Accessing default view from a UIBarButtonItem
/*
UIBarButtonItem does not subclass UIView.
However, there is a way to access the UIBarButtonItem's default view without breaching
Apple's 'Do not use private APIs' rule.
That's because said view responds to KVO, such as changing the tint-color.
*/
/*
After setting your UIBarButton item inside the UINavigationBar object or UIToolBar object,
access your view in the following fashion: