|
9 | 9 | import UIKit |
10 | 10 |
|
11 | 11 | extension UIView { |
12 | | - /// Struct to define center attribute |
13 | | - struct Center: OptionSet { |
14 | | - let rawValue: UInt |
15 | | - static let x = Center(rawValue: 1 << 0) |
16 | | - static let y = Center(rawValue: 1 << 1) |
17 | | - static let all: Center = [.x, .y] |
| 12 | + /// Center alignment options |
| 13 | + public struct Center: OptionSet { |
| 14 | + public let rawValue: UInt |
| 15 | + /// center X |
| 16 | + public static let x = Center(rawValue: 1 << 0) |
| 17 | + /// center Y |
| 18 | + public static let y = Center(rawValue: 1 << 1) |
| 19 | + /// all (both center X and center Y) |
| 20 | + public static let all: Center = [.x, .y] |
| 21 | + // initializer must be declared public to matches a (public init) requirement in protocol 'OptionSet' |
| 22 | + public init(rawValue: UInt) { |
| 23 | + self.rawValue = rawValue |
| 24 | + } |
18 | 25 | } |
19 | 26 |
|
20 | | - /// Constrain the receiving view with provided center attributes |
| 27 | + /// Constrain the center of the receiving view with the center of another view |
21 | 28 | /// - Parameters: |
22 | | - /// - center: Center attribute of view to constrain to (default `.all`) |
23 | | - /// - view2: View object to which constrain to (pass `nil` to constrain to superview) |
24 | | - /// - relation: Relation to evaluate (default `.equal`) |
25 | | - /// - offset: Offset to apply to attribute(center X and Y) (default `.zero`) |
26 | | - /// - priority: Constraint priority (default `.required`) |
27 | | - /// - isActive: Whether to activate the constraint or not (default `true`) |
28 | | - /// - Returns: The created layout constraint |
29 | | - func constrainCenter( |
| 29 | + /// - center: which center attributes to constrain (default `.all`) |
| 30 | + /// - view2: view or layout guide to constrain to (pass `nil` to constrain to superview) |
| 31 | + /// - relation: relation to evaluate (towards view2) (default `.equal`) |
| 32 | + /// - offset: offset to apply relative to view2.center (default `.zero`) |
| 33 | + /// - priority: constraint priority (default `.required`) |
| 34 | + /// - isActive: whether to activate the constraints or not (default `true`) |
| 35 | + /// - Returns: dictionary of constraints created, keyed by `.centerX, .centerY` |
| 36 | + public func constrainCenter( |
30 | 37 | _ center: Center = .all, |
31 | 38 | to view2: Anchorable? = nil, |
32 | 39 | relatedBy relation: NSLayoutConstraint.Relation = .equal, |
|
0 commit comments