File tree Expand file tree Collapse file tree 1 file changed +49
-0
lines changed
Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Original file line number Diff line number Diff line change @@ -679,6 +679,55 @@ extension View {
679679 }
680680}
681681
682+ public extension View {
683+ enum ConstrainStyleHorizontal {
684+ case fill
685+ case pinLeading
686+ case pinTrailing
687+ case center
688+ }
689+ enum ConstrainStyleVertical {
690+ case fill
691+ case pinTop
692+ case pinBottom
693+ case center
694+ }
695+
696+ @inlinable
697+ func addSubview(
698+ _ view: View ,
699+ constrainHorizontal: ConstrainStyleHorizontal ,
700+ constrainVertical: ConstrainStyleVertical ,
701+ insets: Insets = . zero
702+ ) {
703+ self . addSubview ( view)
704+
705+ switch constrainHorizontal {
706+ case . fill:
707+ view. leadingAnchor. constrain ( insets. leading, from: self . leadingAnchor)
708+ view. trailingAnchor. constrain ( - insets. trailing, from: self . trailingAnchor)
709+ case . pinLeading:
710+ view. leadingAnchor. constrain ( insets. leading, from: self . leadingAnchor)
711+ case . pinTrailing:
712+ view. trailingAnchor. constrain ( - insets. trailing, from: self . trailingAnchor)
713+ case . center:
714+ view. centerXAnchor. constrain ( to: self . centerXAnchor)
715+ }
716+
717+ switch constrainVertical {
718+ case . fill:
719+ view. topAnchor. constrain ( insets. top, from: self . topAnchor)
720+ view. bottomAnchor. constrain ( - insets. bottom, from: self . bottomAnchor)
721+ case . pinTop:
722+ view. topAnchor. constrain ( insets. top, from: self . topAnchor)
723+ case . pinBottom:
724+ view. bottomAnchor. constrain ( - insets. bottom, from: self . bottomAnchor)
725+ case . center:
726+ view. centerYAnchor. constrain ( to: self . centerYAnchor)
727+ }
728+ }
729+ }
730+
682731extension View {
683732 public struct CornerMask : OptionSet , Sendable {
684733 public var rawValue : UInt
You can’t perform that action at this time.
0 commit comments