Skip to content

Instantly share code, notes, and snippets.

@stuartjmoore
stuartjmoore / SeparatorView.swift
Created January 27, 2019 17:42
Hairline Separator UIView
//
// SeparatorView.swift
//
// Created by Stuart Moore on 1/26/19.
// Copyright © 2019 Stuart J. Moore. All rights reserved.
//
// Adapted from http://www.figure.ink/blog/2016/9/11/hairlines.
// Published by jemmons on 9/11/16.
//
@stuartjmoore
stuartjmoore / NavigationParallaxTransition.swift
Last active January 18, 2021 08:12
Re-create the Default `UINavigationController` Transition in iOS 10
//
// NavigationParallaxTransition.swift
// NavigationTransition
//
// Created by Stuart Moore on 2/12/17.
// Copyright © 2017 Stuart J. Moore. All rights reserved.
//
import UIKit
@stuartjmoore
stuartjmoore / FontMeasure.swift
Created June 21, 2015 21:54
Fix Clipping UITextView
//: Playground - noun: a place where people can play
import XCPlayground
import UIKit
// MARK: - Paragraph Styles
let headlineParagraphStyle = NSMutableParagraphStyle()
headlineParagraphStyle.lineHeightMultiple = 0.8
@stuartjmoore
stuartjmoore / Readme
Last active August 29, 2015 14:10
UIColor category for iOS 8 keyboard extensions
Moved to https://github.com/stuartjmoore/Keyboard-Resources to allow for images and more files.
- (CGFloat)heightThatFits {
if(!self.text || [self.text isEqualToString:@""])
return 0;
if([self respondsToSelector:@selector(attributedText)]) {
CGSize maxSize = (CGSize){ self.frame.size.width, MAXFLOAT };
CGRect frame = [self.attributedText boundingRectWithSize:maxSize
options:(NSStringDrawingUsesLineFragmentOrigin|
NSStringDrawingUsesFontLeading)
context:nil];
@stuartjmoore
stuartjmoore / WPTextAttachment.h
Last active October 21, 2016 13:08
Creates an NSTextAttachment the takes up the entire width of the line fragment (while maintaining its aspect ratio). Instead of a simple image, any UIView (that has a (CGFloat)heightThatFits method) will work.
//
// WPTextAttachment.h
// ReadArticle
//
// Created by Moore, Stuart on 12/27/13.
// Copyright (c) 2013 The Washington Post. All rights reserved.
//
#import <UIKit/UIKit.h>
@stuartjmoore
stuartjmoore / WPHangingQuoteViewController.m
Last active June 15, 2022 07:29
Hanging quotes on iOS 7.Basically, we set the UITextView's left inset to the negative width of a double quote, then undo that per line fragment if the line doesn't start with a double quote.And the opposite for an exclusion path lines.
- (void)loadOrResizeOrSometing {
/*
* After creating the text view or resizing the font, set the quoteWidth and contentInset.
*/
WPTextContainer *textContainer = (WPTextContainer*)paragraphView.textContainer;
textContainer.spaceWidth = [self widthForCharacter:@" "];
textContainer.charWidths = @{
@(8220) : @([self widthForCharacter:@"“"]),
@(8216) : @([self widthForCharacter:@"‘"]),
@('"') : @([self widthForCharacter:@"\""]),
@stuartjmoore
stuartjmoore / gist:3195007
Created July 28, 2012 22:20
NSScrollView - scrollViewDidBeginScrolling & scrollViewDidEndScrolling
// When you init your view
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(scrollViewDidScroll:) name:NSViewBoundsDidChangeNotification object:scrollView.contentView];
// The methods
- (void)scrollViewDidBeginScrolling
{
// Do stuff
}
@stuartjmoore
stuartjmoore / gist:3067159
Created July 7, 2012 16:44
Help me get thumbnails from Android's running apps?
/*
* This code doesn't work, I'm hoping for some help.
*
* I'm trying to use reflection to dig into Android's @hide classes that store screenshots
* of the currently running apps.
*
* The code compiles and runs perfectly, but mThumbnailReceiver is never called back with
* the bitmaps.
*
* I've never done Android development before (I'm an iOS dev) but I'd love to get this
@stuartjmoore
stuartjmoore / TransparentModalViewController.m
Created October 11, 2011 22:49
A way to show a transparent modal view controller. It's not really transparent, the modal just uses a screenshot as its background.
- (void)showCard:(id)sender
{
UIGraphicsBeginImageContext(self.view.window.frame.size);
[self.view.window.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIViewControllerSubclass *card = [[UIViewControllerSubclass alloc] init];
card.background = screenshot;
[self presentModalViewController:card animated:NO];