Skip to content

Instantly share code, notes, and snippets.

View psobko's full-sized avatar

Piotrek Sobkowski psobko

View GitHub Profile
NSLog(@"### FB SDK VERSION : %@", [[FBRequestConnection class] performSelector:@selector(userAgent)]);
self.gestureRecognizer = [[UITapGestureRecognizer alloc]
initWithTarget:self action:@selector(handleTap:)];
self.gestureRecognizer.numberOfTapsRequired = 1;
[self.view addGestureRecognizer:self.gestureRecognizer];
self.gestureRecognizer.cancelsTouchesInView = NO;
-(void)handleTap:(UITapGestureRecognizer *)recognizer
{
CGPoint translatedPoint = [recognizer locationInView:self.view];
-(void)setEmailFieldBold:(BOOL)bold animated:(BOOL)animated
{
CGFloat fontSize = self.emailTextField.font.pointSize;
void (^setBold)(void) = ^{
self.emailTextField.font = (bold) ? [UIFont QRBoldFontWithSize:fontSize]
: [UIFont QRRegularFontWithSize:fontSize];
};
@psobko
psobko / Block based UIView state animation
Created November 21, 2013 17:12
From Cheddar iOS app
- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
_editing = editing;
self.textField.enabled = !_editing;
void (^change)(void) = ^{
_textField.alpha = _editing ? 0.0f : 1.0f;
_renameListButton.alpha = _editing ? 1.0f : 0.0f;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
if (self.frame.size.width < 500.0f) {
_archiveTasksButton.alpha = _renameListButton.alpha;
@psobko
psobko / navigation bar appearance
Last active June 22, 2016 20:19
Hide navbar shadow
// hide shadow
id navBarAppearance = [UINavigationBar appearance];
[navBarAppearance setBackgroundImage:[UIImage new] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
[navBarAppearance setShadowImage:[UIImage new]];
//custom title
NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont
fontWithName:@"YOURFONT" size:14], NSFontAttributeName,
NSString *htmlFile = [[NSBundle mainBundle] pathForResource:@"sample" ofType:@"html"];
NSString* htmlString = [NSString stringWithContentsOfFile:htmlFile encoding:NSUTF8StringEncoding error:nil];
[webView loadHTMLString:htmlString baseURL:nil];
- (void)loadView
{
[super loadView];
NSArray *nib =[[NSBundle mainBundle]loadNibNamed:@"test" owner:self options:nil];
self.view = [nib objectAtIndex:0];
}
@psobko
psobko / random_number
Created November 14, 2013 01:24
Random Number
//int
int min = 0;
int max = 1;
int i = (arc4random()%(max-min+1))+min;
//BOOL
BOOL i = (arc4random()%(2));
//More Basic
CAGradientLayer *gradient = [CAGradientLayer layer];
gradient.frame = self.view.bounds;
gradient.colors = @[(id)[[UIColor blackColor] CGColor],
(id)[[UIColor whiteColor] CGColor]];
[self.view.layer insertSublayer:gradient atIndex:0];
//More Advanced
+ (void)addLinearGradientToView:(UIView *)theView withColor:(UIColor *)theColor transparentToOpaque:(BOOL)transparentToOpaque
//I created a typedef for a block:
typedef void (^animationCompletionBlock)(void);
// And a key that I use to add a block to an animation:
#define kAnimationCompletionBlock @"animationCompletionBlock"
// Then, if I want to run animation completion code after a CAAnimation finishes, I set myself as the delegate of the animation, and add a block of code to the animation using setValue:forKey:
animationCompletionBlock theBlock = ^void(void)
{