@@ -818,47 +818,99 @@ class PinLayoutImpl: PinLayout {
818818 return self
819819 }
820820
821+ @discardableResult
822+ func marginTop( _ percent: Percent ) -> PinLayout {
823+ func context( ) -> String { return " marginTop( \( percent. description) ) " }
824+ guard let layoutSuperviewRect = layoutSuperviewRect ( context) else { return self }
825+ marginTop = percent. of ( layoutSuperviewRect. height)
826+ return self
827+ }
828+
821829 @discardableResult
822830 func marginLeft( _ value: CGFloat ) -> PinLayout {
823831 marginLeft = value
824832 return self
825833 }
826834
835+ @discardableResult
836+ func marginLeft( _ percent: Percent ) -> PinLayout {
837+ func context( ) -> String { return " marginLeft( \( percent. description) ) " }
838+ guard let layoutSuperviewRect = layoutSuperviewRect ( context) else { return self }
839+ marginLeft = percent. of ( layoutSuperviewRect. width)
840+ return self
841+ }
842+
827843 @discardableResult
828844 func marginBottom( _ value: CGFloat ) -> PinLayout {
829845 marginBottom = value
830846 return self
831847 }
832848
849+ @discardableResult
850+ func marginBottom( _ percent: Percent ) -> PinLayout {
851+ func context( ) -> String { return " marginBottom( \( percent. description) ) " }
852+ guard let layoutSuperviewRect = layoutSuperviewRect ( context) else { return self }
853+ marginBottom = percent. of ( layoutSuperviewRect. height)
854+ return self
855+ }
856+
833857 @discardableResult
834858 func marginRight( _ value: CGFloat ) -> PinLayout {
835859 marginRight = value
836860 return self
837861 }
862+
863+ @discardableResult
864+ func marginRight( _ percent: Percent ) -> PinLayout {
865+ func context( ) -> String { return " marginRight( \( percent. description) ) " }
866+ guard let layoutSuperviewRect = layoutSuperviewRect ( context) else { return self }
867+ marginRight = percent. of ( layoutSuperviewRect. width)
868+ return self
869+ }
838870
839871 @discardableResult
840872 func marginStart( _ value: CGFloat ) -> PinLayout {
841873 return isLTR ( ) ? marginLeft ( value) : marginRight ( value)
842874 }
875+
876+ @discardableResult
877+ func marginStart( _ percent: Percent ) -> PinLayout {
878+ return isLTR ( ) ? marginLeft ( percent) : marginRight ( percent)
879+ }
843880
844881 @discardableResult
845882 func marginEnd( _ value: CGFloat ) -> PinLayout {
846883 return isLTR ( ) ? marginRight ( value) : marginLeft ( value)
847884 }
848885
886+ @discardableResult
887+ func marginEnd( _ percent: Percent ) -> PinLayout {
888+ return isLTR ( ) ? marginRight ( percent) : marginLeft ( percent)
889+ }
890+
849891 @discardableResult
850892 func marginHorizontal( _ value: CGFloat ) -> PinLayout {
851893 marginLeft = value
852894 marginRight = value
853895 return self
854896 }
855897
898+ @discardableResult
899+ func marginHorizontal( _ percent: Percent ) -> PinLayout {
900+ return marginLeft ( percent) . marginRight ( percent)
901+ }
902+
856903 @discardableResult
857904 func marginVertical( _ value: CGFloat ) -> PinLayout {
858905 marginTop = value
859906 marginBottom = value
860907 return self
861908 }
909+
910+ @discardableResult
911+ func marginVertical( _ percent: Percent ) -> PinLayout {
912+ return marginTop ( percent) . marginBottom ( percent)
913+ }
862914
863915 @discardableResult
864916 func margin( _ insets: UIEdgeInsets ) -> PinLayout {
@@ -888,6 +940,11 @@ class PinLayoutImpl: PinLayout {
888940 return self
889941 }
890942
943+ @discardableResult
944+ func margin( _ percent: Percent ) -> PinLayout {
945+ return marginTop ( percent) . marginLeft ( percent) . marginBottom ( percent) . marginRight ( percent)
946+ }
947+
891948 @discardableResult
892949 func margin( _ top: CGFloat , _ left: CGFloat , _ bottom: CGFloat , _ right: CGFloat ) -> PinLayout {
893950 marginTop = top
@@ -897,6 +954,11 @@ class PinLayoutImpl: PinLayout {
897954 return self
898955 }
899956
957+ @discardableResult
958+ func margin( _ top: Percent , _ left: Percent , _ bottom: Percent , _ right: Percent ) -> PinLayout {
959+ return marginTop ( top) . marginLeft ( left) . marginBottom ( bottom) . marginRight ( right)
960+ }
961+
900962 @discardableResult func margin( _ vertical: CGFloat , _ horizontal: CGFloat ) -> PinLayout {
901963 marginTop = vertical
902964 marginLeft = horizontal
@@ -905,6 +967,11 @@ class PinLayoutImpl: PinLayout {
905967 return self
906968 }
907969
970+ @discardableResult
971+ func margin( _ vertical: Percent , _ horizontal: Percent ) -> PinLayout {
972+ return marginVertical ( vertical) . marginHorizontal ( horizontal)
973+ }
974+
908975 @discardableResult func margin( _ top: CGFloat , _ horizontal: CGFloat , _ bottom: CGFloat ) -> PinLayout {
909976 marginTop = top
910977 marginLeft = horizontal
@@ -913,6 +980,11 @@ class PinLayoutImpl: PinLayout {
913980 return self
914981 }
915982
983+ @discardableResult
984+ func margin( _ top: Percent , _ horizontal: Percent , _ bottom: Percent ) -> PinLayout {
985+ return marginTop ( top) . marginHorizontal ( horizontal) . marginBottom ( bottom)
986+ }
987+
916988 @discardableResult
917989 func pinEdges( ) -> PinLayout {
918990 shouldPinEdges = true
0 commit comments