File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed
Sources/YCoreUI/Extensions/UIKit Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change 77//
88
99import UIKit
10+
11+ extension UIView {
12+ /// constrain the aspect ratio for the receiving view
13+ /// - Parameters:
14+ /// - ratio: aspect ratio
15+ /// - offset: offset to apply (default `.zero`)
16+ /// - relation: relation to evaluate (towards dimension) (default `.equal`)
17+ /// - priority: constraint priority (default `.required`)
18+ /// - isActive: whether to activate the constraint or not (default `true`)
19+ /// - Returns: The created layout constraint
20+ @discardableResult public func constrainAspectRatio(
21+ _ ratio: CGFloat ,
22+ offset: CGFloat = 0 ,
23+ relatedBy relation: NSLayoutConstraint . Relation = . equal,
24+ priority: UILayoutPriority = . required,
25+ isActive: Bool = true
26+ ) -> NSLayoutConstraint {
27+ constrain (
28+ . widthAnchor,
29+ to : heightAnchor,
30+ relatedBy : relation,
31+ multiplier: ratio,
32+ constant : offset,
33+ priority: priority,
34+ isActive: isActive
35+ )
36+ }
37+ }
You can’t perform that action at this time.
0 commit comments