Skip to content

Instantly share code, notes, and snippets.

// Start here https://developers.facebook.com/docs/getting-started/getting-started-with-the-ios-sdk/
// Install the Facebook SDK, get it linked up, create an app, and get that setup correctly
// in your info.plist, appDelegate, and build settings.
//Note: This example uses ARC. If you aren't using ARC, made sure to release/retain objects as needed.
//Now for the fun part.
////////////////////////////

Add HeaderView in UICollectionView like UITableView's tableHeaderView:

{
    [self.collectionView registerNib:[UINib nibWithNibName:@"HeaderView" bundle:nil]
          forSupplementaryViewOfKind:UICollectionElementKindSectionHeader
                 withReuseIdentifier: @"HeaderView"];
}
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView   viewForSupplementaryElementOfKind:(NSString *)kind  atIndexPath:(NSIndexPath *)indexPath{
    if ([kind isEqualToString:UICollectionElementKindSectionHeader]){
        UICollectionReusableView *view = [collectionView dequeueReusableSupplementaryViewOfKind:kind   withReuseIdentifier:@"HeaderView" forIndexPath:indexPath];
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSString *info = @"http://codeafterhours.wordpress.com";
// Generation of QR code image
NSData *qrCodeData = [info dataUsingEncoding:NSISOLatin1StringEncoding]; // recommended encoding
CIFilter *qrCodeFilter = [CIFilter filterWithName:@"CIQRCodeGenerator"];
[qrCodeFilter setValue:qrCodeData forKey:@"inputMessage"];
#apks
glob:*.apk
glob:*.ap_
# files for the dex VM
glob:*.dex
# Java class files
glob:*.class
@akdsouza
akdsouza / UILabel with Countdown
Created May 9, 2016 08:07 — forked from dokun1/UILabel with Countdown
UILabel as countdown timer given NSTimeInterval
-(void) updateCountdown {
NSTimeInterval timeToClosing = [_deleteDate timeIntervalSinceDate:[NSDate date]];
div_t h = div(timeToClosing, 3600);
int hours = h.quot;
div_t m = div(h.rem, 60);
int minutes = m.quot;
int seconds = m.rem;
NSString *hoursStr, *minutesStr, *secondsStr;
- (void)observeJSContext
{
CFRunLoopRef runLoop = CFRunLoopGetCurrent();
// This is a idle mode of RunLoop, when UIScrollView scrolls, it jumps into "UITrackingRunLoopMode"
// and won't perform any cache task to keep a smooth scroll.
CFStringRef runLoopMode = kCFRunLoopDefaultMode;
CFRunLoopObserverRef observer = CFRunLoopObserverCreateWithHandler
(kCFAllocatorDefault, kCFRunLoopBeforeWaiting, true, 0, ^(CFRunLoopObserverRef observer, CFRunLoopActivity _) {
@akdsouza
akdsouza / PSPDFUIKitMainThreadGuard.m
Created July 21, 2016 08:07 — forked from steipete/PSPDFUIKitMainThreadGuard.m
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>
/*
Swift Programming Language Guide
"A Swift Tour" Solutions
https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/GuidedTour.html#//apple_ref/doc/uid/TP40014097-CH2-XID_1
These are the solutions to all the "experiments" in the pre-release Swift Programming Guide
(released on the same day Apple announced Swift). A couple of things worth noting:
1. Swift syntax, e.g. array declarations, has changed since I releasd these. So this code will
probably cause some errors when you paste it into a playground. Should be easy enough to fix
@akdsouza
akdsouza / AppDelegate.m
Created November 7, 2017 09:13 — forked from brunojppb/AppDelegate.m
Allow landscape mode in specific ViewControllers
/* Allow Landscape mode for specific ViewControllers */
-(UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
UIViewController* topVC = [self topViewControllerWith: self.window.rootViewController];
if ([topVC respondsToSelector:@selector(canRotate)]) {
return UIInterfaceOrientationMaskAllButUpsideDown;
}
return UIInterfaceOrientationMaskPortrait;
}
/* get the top ViewController */
@akdsouza
akdsouza / rotatable.swift
Created November 7, 2017 09:13 — forked from ajself/rotatable.swift
Rotate UIViewControllers that conform to a protocol
/*
This is an update to an example found on http://www.jairobjunior.com/blog/2016/03/05/how-to-rotate-only-one-view-controller-to-landscape-in-ios-slash-swift/
The code there works, with some updating to the latest Swift, but the pattern isn't very Swifty. The following is what I found to be more helpful.
*/
/*
First, create a protocol that UIViewController's can conform to.
This is in opposition to using `Selector()` and checking for the presence of an empty function.
*/