Skip to content

Instantly share code, notes, and snippets.

@dtrauger
dtrauger / ios-custom-url-protocol
Created November 17, 2014 15:19
Custom URL Protocol to Globally Modify User Agent for URL Requests
@interface CustomBrowserURLProtocol : NSURLProtocol
@end
@interface CustomBrowserURLProtocol ()
@property (nonatomic, strong) NSURLConnection *connection;
@end
@implementation CustomBrowserURLProtocol
@dtrauger
dtrauger / get-android-version
Created November 14, 2014 16:48
Get Android Version
//http://developer.android.com/reference/android/os/Build.VERSION.html
android.os.Build.VERSION.CODENAME //the current development codename, or the string "REL" if this is a release build.
android.os.Build.VERSION.INCREMENTAL //the internal value used by the underlying source control to represent this build.
android.os.Build.VERSION.RELEASE //the user-visible version string.
@dtrauger
dtrauger / ios-add-border-to-view
Last active March 25, 2022 19:29
Programatically Adding Border to View in Objective C
CALayer *topBorder = [CALayer layer];
topBorder.frame = CGRectMake(0.0f, 0.0, viewForBorder.frame.size.width, 1.0f);
topBorder.borderWidth = 1;
topBorder.borderColor = [UIColor colorWithRed:58.0/255.0 green:58.0/255.0 blue:58.0/255.0 alpha:1.0].CGColor;
[theView.layer addSublayer:topBorder];
@dtrauger
dtrauger / ios-create-gradient-background
Last active June 24, 2020 14:45
Create Gradient Background for View in Objective C
// Create the colors
UIColor *topColor = [UIColor colorWithRed:50.0/255.0 green:50.0/255.0 blue:50.0/255.0 alpha:1.0];
UIColor *bottomColor = [UIColor colorWithRed:56.0/255.0 green:56.0/255.0 blue:56.0/255.0 alpha:1.0];
// Create the gradient
CAGradientLayer *theViewGradient = [CAGradientLayer layer];
theViewGradient.colors = [NSArray arrayWithObjects: (id)topColor.CGColor, (id)bottomColor.CGColor, nil];
theViewGradient.frame = theView.bounds;
//Add gradient to view