Skip to content

Instantly share code, notes, and snippets.

View bdalziel's full-sized avatar

Ben Dalziel bdalziel

View GitHub Profile
@bdalziel
bdalziel / gist:2293724
Created April 3, 2012 17:07
Work around for iOS iframe growth
html,
body,
#doc {
height: 100%; // Passes through the height of the parent iframe element
}
#doc {
// Magic to prevent iOS growing the iFrame to fit the content.
// This container will mimic the behavior of the iframe on a desktop browser
-webkit-overflow-scrolling:touch;
overflow-y: scroll;
//
// ColorUtil.swift
// FantasyMovieLeague
//
// Created by Ben Dalziel on 2/17/16.
// Copyright © 2016 Kinetoplay. All rights reserved.
//
import SwiftHEXColors
//
// FontUtil.swift
// FantasyMovieLeague
//
// Created by Ben Dalziel on 2/17/16.
// Copyright © 2016 Kinetoplay. All rights reserved.
//
import UIKit
@bdalziel
bdalziel / gist:3005482
Created June 27, 2012 17:16
Avoiding flicker on -webkit-overflow-scrolling: touch; content
li {
-webkit-backface-visibility: hidden;
-webkit-transform: translate3d(0,0,0);
}
@bdalziel
bdalziel / gist:3005518
Created June 27, 2012 17:22
Simple horizontal scroll with native feel and no flicker following transitions
#issues {
width: 100%;
max-width: 100%;
white-space: nowrap;
overflow: hidden;
overflow-x: scroll;
-webkit-overflow-scrolling:touch;
ul, li {
+ (CGFloat)getUITextElementAboveBaselineHeight:(ASPUITextElement)element traitCollection:(UITraitCollection *)contextTraitCollection {
ASPUITextStyle elementTextStyle = [self mapUIElementToStyle:element elementVariation:ASPUITextElementVariationDefault];
UIFont *font = [ASPFontUtil getUIFont:elementTextStyle traitCollection:contextTraitCollection];
CGFloat lineHeightMultiple = [self getUILineHeightMultiple:elementTextStyle font:font traitCollection:contextTraitCollection];
CGFloat lineHeightAdjustment = 0.0;
if (lineHeightMultiple != 1) {
lineHeightAdjustment = (font.lineHeight - (font.lineHeight * lineHeightMultiple))/2;
}
// Between Title and Description
// 1. Get height below title baseline which is poking out below a grid line - get the value that would make this poke a whole 8 px.
CGFloat titleDescenderRoundedToNextGridline = 8 - fmod([ASPFontUtil getUITextElementBelowBaselineHeight:ASPUITextElementContentCardTitle traitCollection:contextTraitCollection], 8) ;
// 2. Get height above description baseline that is poking above a grid line - get the value that would make this poke a whole 8 px.
CGFloat descriptionAscenderRoundedToNextGridline = 8 - fmod([ASPFontUtil getUITextElementAboveBaselineHeight:ASPUITextElementContentCardDescription traitCollection:contextTraitCollection], 8) ;
// 3. Round sum of nudges (top and bottom), and make sure we're not putting more than a single grid spacing between them
CGFloat belowTitleMargin = [ASPUtil roundToSubPixelPrecision:titleDescenderRoundedToNextGridline + descriptionAscenderRoundedToNextGridline deviceScale:deviceScale];
if (belowTitleMargin > 8.
+ (CGFloat)getUITextElementBelowBaselineHeight:(ASPUITextElement)element traitCollection:(UITraitCollection *)contextTraitCollection {
// 1. Get the style guide typography style we're using for this UI element
ASPUITextStyle elementTextStyle = [self mapUIElementToStyle:element elementVariation:ASPUITextElementVariationDefault];
UIFont *font = [ASPFontUtil getUIFont:elementTextStyle traitCollection:contextTraitCollection];
// 2. Get line height multiple for typography - this is important because line height affects descender and ascender calculations
CGFloat lineHeightMultiple = [self getUILineHeightMultiple:elementTextStyle font:font traitCollection:contextTraitCollection];
// 3. If we're using a non-default line height, calculate an adjusment
CGFloat lineHeightAdjustment = 0.0;
// 1. We're trying to align the baseline of the description label with a gridline this far from the bottom of the Content Card
CGFloat targetBottomMargin = smallMargin;
// 2. We need to know how far to nudge the label down. This is a calculation dependent on the UI traits, and is specific to the typography we're using for the description label
CGFloat descriptionLabelBaselineAdjustmentHeight = [ASPFontUtil getUITextElementBelowBaselineHeight:ASPUITextElementContentCardDescription traitCollection:contextTraitCollection];
// 3. Font measurements aren't nice round numbers. I have a utility to round floats to numbers the UI can resonable render at (sub pixel), which is dependent on device scale
CGFloat bottomMargin = [ASPUtil roundToSubPixelPrecision:(targetBottomMargin - descriptionLabelBaselineAdjustmentHeight) deviceScale:deviceScale];
// 4. Use our dynamically adjusted bottom margin and hope it works
self.contentCard.layoutMargins = UIEdgeInsetsMake(smallMargin, gutterWidth, bo
- (void)handleMargins:(UITraitCollection *)contextTraitCollection {
// 1. Get hold of a bunch of sizes based on the traits of the context we're rendering in
CGFloat deviceScale = [UIScreen mainScreen].scale;
CGFloat smallMargin = [ASPSpacingUtil getSpacing:ASPSpacingSizeSmall traitCollection:contextTraitCollection];
CGFloat gutterWidth = [ASPSpacingUtil getGutterWidth:contextTraitCollection];
CGFloat horizontalMargin = [ASPSpacingUtil getLeftAndRightCellMargins:contextTraitCollection];
// 2. Setup containing margins
// Zero out cell margins, and set horizontal indent on contentview - important for the transition from full bleed to gutters (regular class sizes such as iPad portrait)