Skip to content

Instantly share code, notes, and snippets.

@JunyuKuang
Created November 21, 2021 02:55
Show Gist options
  • Save JunyuKuang/11bb90f92933b5fb85fa0d3620733bf9 to your computer and use it in GitHub Desktop.
Save JunyuKuang/11bb90f92933b5fb85fa0d3620733bf9 to your computer and use it in GitHub Desktop.
Helper methods for NSLayoutConstraint
//
// NSLayoutConstraint+.swift
// SpringUI
//
// Created by Jonny Kuang on 11/21/21.
// Copyright © 2021 Jonny Kuang. All rights reserved. (MIT license)
//
import Foundation
extension NSLayoutConstraint {
/// e.g. `UIView().heightAnchor.constraint(equalToConstant: 44).kjy_withPriority(.defaultHigh).isActive = true`
func kjy_withPriority(_ priority: UILayoutPriority) -> NSLayoutConstraint {
self.priority = priority
return self
}
}
/// e.g. `let notSoHighPriority = UILayoutPriority.defaultHigh - 1`
func + (priority: UILayoutPriority, difference: Float) -> UILayoutPriority {
UILayoutPriority(priority.rawValue + difference)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment