Skip to content

Commit 53eb2e2

Browse files
committed
Improved documentation comment and fixed control
1 parent 8ad1a30 commit 53eb2e2

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

Sources/YCoreUI/Extensions/UIKit/UIView+constrainCenter.swift

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,31 @@
99
import UIKit
1010

1111
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+
}
1825
}
1926

20-
/// Constrain the receiving view with provided center attributes
27+
/// Constrain the center of the receiving view with the center of another view
2128
/// - 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(
3037
_ center: Center = .all,
3138
to view2: Anchorable? = nil,
3239
relatedBy relation: NSLayoutConstraint.Relation = .equal,

0 commit comments

Comments
 (0)