Skip to content

Instantly share code, notes, and snippets.

@stuartjmoore
stuartjmoore / SeparatorView.swift
Created Jan 27, 2019
Hairline Separator UIView
View SeparatorView.swift
//
// 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 Jan 18, 2021
Re-create the Default `UINavigationController` Transition in iOS 10
View NavigationParallaxTransition.swift
//
// 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 Jun 21, 2015
Fix Clipping UITextView
View FontMeasure.swift
//: 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 Aug 29, 2015
UIColor category for iOS 8 keyboard extensions
View Readme
Moved to https://github.com/stuartjmoore/Keyboard-Resources to allow for images and more files.
View UILabel+Resize.m
- (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 Oct 21, 2016
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.
View WPTextAttachment.h
//
// 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 Nov 9, 2016
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.
View WPHangingQuoteViewController.m
- (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 Jul 28, 2012
NSScrollView - scrollViewDidBeginScrolling & scrollViewDidEndScrolling
View gist:3195007
// 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 Jul 7, 2012
Help me get thumbnails from Android's running apps?
View gist:3067159
/*
* 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 Oct 11, 2011
A way to show a transparent modal view controller. It's not really transparent, the modal just uses a screenshot as its background.
View TransparentModalViewController.m
- (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];