Skip to content

Instantly share code, notes, and snippets.

View uberbruns's full-sized avatar

Karsten Bruns uberbruns

View GitHub Profile
@uberbruns
uberbruns / NonBouncingTableViewCell.m
Last active December 20, 2015 14:29
Makes the first row of an UITableView ignoring the bounce effect, like the gallery for highlights in the AppStore App.
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
if (scrollView.contentOffset.y < 0) {
UIView * firstCell = [_tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
firstCell.frame = ({
CGRect frame = firstCell.frame;
frame.origin.y = 0;
[_tableView.superview convertRect:frame toView:firstCell.superview];
});
@uberbruns
uberbruns / UBRShiftRange
Created October 14, 2013 18:51
Calculates how a given NSRange is affected by replacing another range with a defined length in the same context. It's a little bit like `replaceCharactersInRange:withString:` but the receiver/result is not a string but a NSRange.
static inline NSRange UBRShiftRange(NSRange range, NSRange replacedRange, NSUInteger insertedLength) {
if (replacedRange.location > range.location + range.length) {
// Following
return range;
}
NSRange intersection = NSIntersectionRange(range, replacedRange);
@uberbruns
uberbruns / BlankBackBarButtonText.m
Created October 18, 2013 19:22
A simple way to remove the backBarButtonTitle on iOS7.
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
UIBarButtonItem * barButton = [[UIBarButtonItem alloc] init];
barButton.title = @"";
self.navigationItem.backBarButtonItem = barButton;
}
@uberbruns
uberbruns / testassets.rb
Last active September 11, 2016 06:02
iOS Retina Assets Test
require 'fileutils'
path = ARGV[0]
ok = 0
fail = 0
Dir.glob("#{path}/*.png", File::FNM_DOTMATCH) do |f|
unless f.end_with? "@2x.png"
<?php
/***********************************************************************************************
* Tweetledee - Incredibly easy access to Twitter data
* userrss.php -- User timeline results formatted as a RSS feed
* Version: 0.3.0
* Copyright 2013 Christopher Simpkins
* MIT License
************************************************************************************************/
/*-----------------------------------------------------------------------------------------------
==> Instructions:
override func shouldPerformSegueWithIdentifier(identifier: String!, sender: AnyObject!) -> Bool {
let needsNavigationController = (splitViewController.traitCollection.horizontalSizeClass == .Regular)
if identifier == "ShowDetail" && needsNavigationController {
performSegueWithIdentifier("ShowDetailWithNavigationController", sender: sender)
return false;
}
return super.shouldPerformSegueWithIdentifier(identifier, sender: sender)
override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) {
var detailViewContoller: UIViewController?
if (segue.identifier == "ShowDetail") {
detailViewContoller = segue.destinationViewController as? UIViewController
} else if (segue.identifier == "ShowDetailWithNavigationController") {
let navigationController = segue.destinationViewController as UINavigationController
detailViewContoller = navigationController.viewControllers[0] as? UIViewController
}
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
let rootViewController = RootViewController()
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
@uberbruns
uberbruns / popWebAPI.swift
Last active August 29, 2015 14:23
A draft on how to use Protocol-Oriented Programming in Swift 2 with a web API
import UIKit
// We define a APIResultType as something that can be generated from a JSON
protocol APIResultType {
init?(json: String)
}
import Foundation
class BaseClass : Equatable {
var stringValue: String = ""
}
class SubClass : BaseClass {
var intValue: Int = 0
}