Skip to content

Instantly share code, notes, and snippets.

@sdpjswl
sdpjswl / UIButton insets - Title below image
Last active August 29, 2015 14:18
Programatically adjust title and image insets of button so that they appear centred and title below the image
- (void)fixTitleAndImageInsetsForButton:(UIButton *)btn {
// the space between the image and text
CGFloat spacing = 6.0;
// lower the text and push it left so it appears centered
// below the image
CGSize imageSize = btn.imageView.image.size;
btn.titleEdgeInsets = UIEdgeInsetsMake(0.0, - imageSize.width, - (imageSize.height + spacing), 0.0);
@sdpjswl
sdpjswl / MMDrawerController wokaround
Created April 3, 2015 11:02
Having a table inside a navigation controller in the left drawer of an MMDrawerController causes it to jump for the first time
either:
1. in viewWillAppear:
[self.navigationController.view layoutSubviews];
or
2. in viewDidLoad:
self.navigationController.navigationBar.translucent = NO;
@sdpjswl
sdpjswl / NSURLSession+CancelTasks.h
Created April 1, 2015 10:29
How to cancel all running tasks in an NSURLSession
//
// NSURLSession+CancelTasks.h
// Networking
//
// Created by sudeep on 31/03/15.
// Copyright (c) 2015 Sudeep Jaiswal. All rights reserved.
//
@import Foundation;
@sdpjswl
sdpjswl / To-do
Last active August 29, 2015 14:17
Topics to study
// reactive cocoa
http://www.raywenderlich.com/62699/reactivecocoa-tutorial-pt1
// tutorials
http://chrisrisner.com/31-Days-of-iOS
// autolayout
http://angelovillegas.com/2014/01/31/ios-nslayoutconstraint
@sdpjswl
sdpjswl / Resign first responder
Created March 18, 2015 08:09
Resign whoever the first responder is
[[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder) to:nil from:nil forEvent:nil];
[self.view endEditing:YES];
[self.view.window endEditing:YES];
// source: http://stackoverflow.com/questions/1823317/get-the-current-first-responder-without-using-a-private-api
@sdpjswl
sdpjswl / Predicate search
Last active August 29, 2015 14:17
How to filter an array using predicates
@sdpjswl
sdpjswl / Disable ARC
Created March 16, 2015 06:46
How to disable ARC on particular files
in build phases ---> compile sources:
- navigate to the file(s) you want to disable arc on
- add to their compiler flags; '-fno-objc-arc'
@sdpjswl
sdpjswl / CocoaPods crash course
Last active August 29, 2015 14:17
A crash course to get started with CocoaPods
1. sudo gem install cocoapods // install command line tool (do this just once)
2. pod setup // clones the pod repo locally (do this just once)
3. in a project folder, 'pod init' // creates a podfile
4. in the podfile, add pod names, eg: pod 'AFNetworking'
5. in the project folder on terminal, 'pod install'
@sdpjswl
sdpjswl / Testflight crash
Created March 13, 2015 12:50
Builds crashing on Testflight but not on simulator
occurs due to compiler optimisation settings:
build settings ---> apple llvm 6.0 - code generation
or just search for "optimization"
the issue lies in "optimization level". testflight builds use the "release" configuration which uses a different level than our usual debug.
solutions:
@sdpjswl
sdpjswl / Constraints
Created March 12, 2015 05:29
How to outlet constraints and animate constraint changes
[self.view layoutIfNeeded]; // always call on self.view
_constraintObject.constant = 44; // change the constraint value
[UIView animateWithDuration:0.25
animations:^{
[self.view layoutIfNeeded]; // call again to update the layout
}];
sources:
http://stackoverflow.com/questions/12622424/how-do-i-animate-constraint-changes
http://stackoverflow.com/questions/22086054/unable-to-make-outlet-connection-to-a-constraint-in-ib