Skip to content

Instantly share code, notes, and snippets.

View mjjimenez's full-sized avatar

Mark Jimenez mjjimenez

View GitHub Profile
@leviathan
leviathan / Load UIView with nib
Created January 7, 2011 14:53
Loading a custom UIView class with a custom nib file.
QPickOneView* myView = nil;
NSArray* nibViews = [[NSBundle mainBundle] loadNibNamed:@"QPickOneView" owner:self options:nil];
for (id currentObject in nibViews) {
if ([currentObject isKindOfClass:[QPickOneView class]]) {
myView = (QPickOneView *) currentObject;
break;
}
}
@zbyhoo
zbyhoo / solve_pbxproj_merge_conflict.sh
Created May 5, 2011 09:00
Solving pbxproj files git merge conflicts when two users add files at the same time.
#!/bin/sh
projectfile=`find -d . -name 'project.pbxproj'`
projectdir=`echo *.xcodeproj`
projectfile="${projectdir}/project.pbxproj"
tempfile="${projectdir}/project.pbxproj.out"
savefile="${projectdir}/project.pbxproj.mergesave"
cat $projectfile | grep -v "<<<<<<< HEAD" | grep -v "=======" | grep -v "^>>>>>>> " > $tempfile
cp $projectfile $savefile
@erans
erans / UIImage+Resize.m
Created November 7, 2011 07:10
UIImage+Resize.m Fix for Rotation / Orientation on iOS 5
- (UIImage *)resizedImage:(CGSize)newSize interpolationQuality:(CGInterpolationQuality)quality {
BOOL drawTransposed;
CGAffineTransform transform = CGAffineTransformIdentity;
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 5.0) {
// Apprently in iOS 5 the image is already correctly rotated, so we don't need to rotate it manually
drawTransposed = NO;
} else {
switch (self.imageOrientation) {
case UIImageOrientationLeft:
@rudyjahchan
rudyjahchan / NSObject_Swizzle.h
Last active August 13, 2016 08:29
Monkey-Patching iOS with Objective-C Categories Part III: Swizzling
#import <Foundation/Foundation.h>
@interface NSObject (Swizzle)
+ (void)swizzleInstanceSelector:(SEL)originalSelector
withNewSelector:(SEL)newSelector;
@end
@steipete
steipete / PSPDFUIKitMainThreadGuard.m
Last active May 27, 2024 12:11
This is a guard that tracks down UIKit access on threads other than main. This snippet is taken from the commercial iOS PDF framework http://pspdfkit.com, but relicensed under MIT. Works because a lot of calls internally call setNeedsDisplay or setNeedsLayout. Won't catch everything, but it's very lightweight and usually does the job.You might n…
// Taken from the commercial iOS PDF framework http://pspdfkit.com.
// Copyright (c) 2014 Peter Steinberger, PSPDFKit GmbH. All rights reserved.
// Licensed under MIT (http://opensource.org/licenses/MIT)
//
// You should only use this in debug builds. It doesn't use private API, but I wouldn't ship it.
// PLEASE DUPE rdar://27192338 (https://openradar.appspot.com/27192338) if you would like to see this in UIKit.
#import <objc/runtime.h>
#import <objc/message.h>
@Marlunes
Marlunes / resize_image
Created July 4, 2013 06:24
RESIZING IMAGE PROPORTIONALLY
/* To call:
resizedImage = [self imageByScalingProportionallyToSize:myImageView.size usingImage:myImage];
*/
//Method:
- (UIImage *)imageByScalingProportionallyToSize:(CGSize)targetSize usingImage:(UIImage *)image{
UIImage *sourceImage = image;
@Marlunes
Marlunes / customize_picker
Created July 4, 2013 06:30
CUSTOMIZE PICKERVIEW TEXT/CONTENT
// Implement pickerview delegate
// Add some stuffs inside
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{
UILabel *pickerLabel = (UILabel *)view;
CGRect frame = CGRectMake(0,0,250,40);
pickerLabel = [[UILabel alloc] initWithFrame:frame];
[pickerLabel setTextAlignment:UITextAlignmentCenter];
@Marlunes
Marlunes / alert_message
Created July 4, 2013 06:53
ALERT MESSAGE
/*
To call:
[self showErrorWithTitle:@"Error" withMessage:@"Your Device Sucks!"];
*/
- (void)showErrorWithTitle:(NSString *)title withMessage:(NSString *)message{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:title message:message delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
@Marlunes
Marlunes / sqlite_addDB
Created July 4, 2013 07:01
ADDING SQLite DATABASE
//all stuffs will be on the Appdelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//some appdelegate codes here......
[self checkDatabaseIfExists]; //Makes sure that the app has a database
//some appdelegate codes here ......
@Marlunes
Marlunes / Core_data_migration
Created July 9, 2013 09:03
CORE DATA MIGRATION
//in AppDelegate.m
// Add this inside NSPersistenStoreCoordinator delegate
/* Note: NSPersistenStoreCoordinator delegate is automatically created if you create
empty application and selected "use Core Data"
*/
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES],