Created
November 21, 2021 02:55
-
-
Save JunyuKuang/11bb90f92933b5fb85fa0d3620733bf9 to your computer and use it in GitHub Desktop.
Helper methods for NSLayoutConstraint
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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