Skip to content

Instantly share code, notes, and snippets.

@EmperiorEric
EmperiorEric / NSLayoutConstraint+StandardMetrics.swift
Last active February 19, 2020 01:44
A simple extension I wrote that makes working with visual format for AutoLayout much more enjoyable.
//
// NSLayoutConstraint+StandardMetrics.swift
//
// Created by Ryan Poolos on 4/22/15.
// Copyright (c) 2015 Frozen Fire Studios, Inc. All rights reserved.
//
import UIKit
extension Double {
@EmperiorEric
EmperiorEric / UICollectionViewCellSubclass
Created July 13, 2013 13:38
Looking for an elegant way to make two views dependent on each other, without being the triggers that create them. Basically in a UITableViewCell I have two labels that appear side-by-side. Their frames are obviously dependent on each other for this reason, but either could be nonexistent based. I calling self.label would lazy init them so you'd…
- (UILabel *)titleLabel
{
if (!_titleLabel) {
CGFloat width = CGRectGetMinX(_detailLabel.frame);
_titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, width, CGRectGetHeight(self.infoView.bounds))];
[self.infoView addSubview:_titleLabel];
}
@EmperiorEric
EmperiorEric / ExampleA.m
Created June 16, 2013 00:24
So I've seen both of these options from time to time, and I'm wondering if there is something inherently wrong with an option, if there is some non obvious benefit, or if it is entirely a preference based decision.
- (id)initWithProperty:(id)property
{
self = [super init];
if (self) {
self.property = property;
}
return self;
}
- (id)initWithProperty:(id)property otherProperty:(id)otherProperty
// By Erik Andersson
// Please help with this method to bring support for more UILineBreakModes and text alignment
@implementation UILabel (Fix)
- (CGRect)rectForLetterAtIndex:(NSUInteger)index
{
NSAssert(self.lineBreakMode != UILineBreakModeClip, @"UILabel.lineBreakMode cannot be UILineBreakModeClip to calculate the rect of a character. You might think that it's possible, seeing as UILineBreakModeWordWrap is supported, and they are almost the same. But the semantics are weird. Sorry.");
NSAssert(self.lineBreakMode != UILineBreakModeHeadTruncation, @"UILabel.lineBreakMode cannot be UILineBreakModeHeadTruncation to calculate the rect of a character. We can't have everything you know.");
NSAssert(self.lineBreakMode != UILineBreakModeMiddleTruncation, @"UILabel.lineBreakMode cannot be UILineBreakModeMiddleTruncation to calculate the rect of a character. We can't have everything you know.");