Skip to content

Instantly share code, notes, and snippets.

View jlcampana's full-sized avatar
:octocat:
emu emu emu...

Jose Luis Campaña jlcampana

:octocat:
emu emu emu...
View GitHub Profile
@jlcampana
jlcampana / gist:3618043
Created September 4, 2012 07:37
KVO (ejemplo)
//Vamos a observar la propiedad cartUnits del objeto _product
[_product addObserver:self forKeyPath:@"cartUnits" options:NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld context:nil];
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if([keyPath isEqualToString:@"cartUnits"])
{
//Acción
}
}
@jlcampana
jlcampana / gist:3609629
Created September 3, 2012 14:16
Calcular el ancho de una label
CGSize expectedLabelSize = [yourString sizeWithFont:yourLabel.font
constrainedToSize:maximumLabelSize
lineBreakMode:yourLabel.lineBreakMode];
@jlcampana
jlcampana / gist:3607635
Created September 3, 2012 07:35
Crear una vista a partir de un XIB
ProductView *v = [[[NSBundle mainBundle] loadNibNamed:@"ProductView" owner:self options:nil] objectAtIndex:0];
@jlcampana
jlcampana / gist:3449957
Created August 24, 2012 12:18
Animation
[UIView animateWithDuration:DURATION
delay:0.0
options: UIViewAnimationCurveEaseOut
animations:^{
}
completion:^(BOOL finished){
}];
@jlcampana
jlcampana / gist:3447423
Created August 24, 2012 08:19
Present a modal view controller with size<screen size
//Assuming the view controller's size is WIDTHxHEIGHT
//Calling the view Controller:
CustomViewController *vc = [[CustomViewController alloc] init];
vc.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentModalViewController:vc animated:YES];
//In the view controller:
-(void)viewWillAppear:(BOOL)animated
{
@jlcampana
jlcampana / UIImage+Extensions.h
Created August 24, 2012 06:16
UIImage+Extensions.h
//
// UIImage-Extensions.h
//
// Created by Hardy Macia on 7/1/09.
// Copyright 2009 Catamount Software. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface UIImage (CS_Extensions)
- (UIImage *)imageAtRect:(CGRect)rect;
@jlcampana
jlcampana / UIImage+Extensions.m
Created August 24, 2012 06:15
UIImage+Extensions.m
//
// UIImage-Extensions.m
//
// Created by Hardy Macia on 7/1/09.
// Copyright 2009 Catamount Software. All rights reserved.
//
#import "UIImage-Extensions.h"
CGFloat DegreesToRadians(CGFloat degrees) {return degrees * M_PI / 180;};
@jlcampana
jlcampana / gist:3446424
Created August 24, 2012 06:14
Grados a radianes
static inline double radians (double degrees) {return degrees * M_PI/180;}
@jlcampana
jlcampana / gist:3433452
Created August 23, 2012 06:35
Formula to find the width of UILabel with the text length
Formula to find the width of UILabel with the text length
#define MY_LABEL_FONT_SIZE 18
#define MY_LABEL_TEXT_WIDTH_MULTIPLIER(MY_LABEL_FONT_SIZE/2 + 1)
For example if we have a String of length 8 characters then we can find the width of the UILabel which can fit the text as :
8* MY_LABEL_TEXT_WIDTH_MULTIPLIER
and setting the Font Size of the UILabel text as MY_LABEL_FONT_SIZE
@jlcampana
jlcampana / gist:3433394
Created August 23, 2012 06:30
cellForRowAtIndexPath (iOS5 ver)
- (UITableViewCell*) tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
static NSString* customCellIdentifier = @"CustomCellIdentifier";
CustomCell* cell = (CustomCell *) [tableView dequeueReusableCellWithIdentifier:customCellIdentifier];
if (cell == nil)// tableview not associated (registered) with nib file.
{
UINib* customCellNib = [UINib nibWithNibName:@"CustomCell" bundle:nil]; // Register this nib file with cell identifier.
[tableView registerNib: customCellNib forCellReuseIdentifier:customCellIdentifier];
}