Skip to content

Instantly share code, notes, and snippets.

View gnou's full-sized avatar

Mingyu Cui gnou

View GitHub Profile
@gnou
gnou / TextSize.swift
Created March 21, 2017 10:09
Calculate height of some text when width is fixed
public struct TextSize {
fileprivate struct CacheEntry: Hashable {
let text: String
let font: UIFont
let width: CGFloat
let insets: UIEdgeInsets
fileprivate var hashValue: Int {
return text.hashValue ^ Int(width) ^ Int(insets.top) ^ Int(insets.left) ^ Int(insets.bottom) ^ Int(insets.right)