Skip to content

Instantly share code, notes, and snippets.

View mpospese's full-sized avatar

Mark Pospesel mpospese

View GitHub Profile

Introducing YMatterType

YMatterType is a framework that assists in getting typography done right when constructing iOS user interfaces from Figma-based designs.

YMatterType aims to achieve the following goals:

  • Support line height and other typographical properties (letter spacing, text decorations, text cases, and more) across labels, buttons, text fields, and text views.
  • Support Dynamic Type scaling and Accessibility Bold Text on custom fonts
  • Accelerate accurate translation of Figma designs into code by having text-based elements with the exact same intrinsic size (based upon line height) as the corresponding elements in Figma.

Typography

@mpospese
mpospese / UIView+LayoutConstraints.swift
Last active November 9, 2019 02:37
Declarative Auto Layout extension to UIView
import UIKit
extension UIView {
// Declarative Auto Layout helper. Does the same thing as creating a layout constraint but feels more intuitive.
// Also, it remembers to set translatesAutoresizingMaskIntoConstraints = false and allows you to set a constraint's
// priority all in a single method call
// Plus you also don't have to worry about activating the constraint
// Returns: the created constraint in case you wish to hold onto it
@discardableResult public func pin(_ attr1: NSLayoutConstraint.Attribute, to attr2: NSLayoutConstraint.Attribute = .notAnAttribute, of view2: Any? = nil, relatedBy relation: NSLayoutConstraint.Relation = .equal, multiplier: CGFloat = 1, constant c: CGFloat = 0, priority: UILayoutPriority = UILayoutPriority.required, isActive: Bool = true) -> NSLayoutConstraint {
@mpospese
mpospese / Tomato_Basil_Cream_Sauce.md
Created October 30, 2015 22:12
Tomato-basil cream sauce

Ingredients

  • 2-3 cloves garlic, minced
  • 1/3 cup dry white wine
  • 1 pint heavy cream
  • 1 medium tomato (or 2 Roma tomatoes)
  • 1 tablespoon butter
  • 5-6 leaves fresh basil, chopped
  • parmesan cheese
  • salt and pepper to taste
// public interface
@interface UBNTDiscardableThumbnail : NSObject<NSDiscardableContent>
+ (instancetype)discardableThumbnailWithImage:(UIImage *)image;
- (instancetype)initWithImage:(UIImage *)thumbnail;
@property (nonatomic, readonly) UIImage *thumbnail;
@end
@mpospese
mpospese / CGRectIntegralScaled.m
Created February 28, 2013 03:34
Pixel aligns rectangles, taking the device's screen scale into account.
CGRect CGRectIntegralScaledEx(CGRect rect, CGFloat scale)
{
return CGRectMake(floorf(rect.origin.x * scale) / scale, floorf(rect.origin.y * scale) / scale, ceilf(rect.size.width * scale) / scale, ceilf(rect.size.height * scale) / scale);
}
CGRect CGRectIntegralScaled(CGRect rect)
{
return CGRectIntegralScaledEx(rect, [[UIScreen mainScreen] scale]);
}