diff --git a/Source/ConstraintConstantTarget.swift b/Source/ConstraintConstantTarget.swift index 7224df9..24052ae 100644 --- a/Source/ConstraintConstantTarget.swift +++ b/Source/ConstraintConstantTarget.swift @@ -106,18 +106,22 @@ extension ConstraintConstantTarget { if let value = self as? ConstraintInsets { #if os(iOS) || os(tvOS) switch layoutAttribute { - case .left, .leftMargin, .centerX, .centerXWithinMargins: + case .left, .leftMargin: return value.left - case .top, .topMargin, .centerY, .centerYWithinMargins, .lastBaseline, .firstBaseline: + case .top, .topMargin, .firstBaseline: return value.top case .right, .rightMargin: return -value.right - case .bottom, .bottomMargin: + case .bottom, .bottomMargin, .lastBaseline: return -value.bottom case .leading, .leadingMargin: return (ConstraintConfig.interfaceLayoutDirection == .leftToRight) ? value.left : value.right case .trailing, .trailingMargin: return (ConstraintConfig.interfaceLayoutDirection == .leftToRight) ? -value.right : -value.left + case .centerX, .centerXWithinMargins: + return (value.left - value.right) / 2 + case .centerY, .centerYWithinMargins: + return (value.top - value.bottom) / 2 case .width: return -(value.left + value.right) case .height: @@ -131,18 +135,22 @@ extension ConstraintConstantTarget { } #else switch layoutAttribute { - case .left, .centerX: + case .left: return value.left - case .top, .centerY, .lastBaseline, .firstBaseline: + case .top, .firstBaseline: return value.top case .right: return -value.right - case .bottom: + case .bottom, .lastBaseline: return -value.bottom case .leading: return (ConstraintConfig.interfaceLayoutDirection == .leftToRight) ? value.left : value.right case .trailing: return (ConstraintConfig.interfaceLayoutDirection == .leftToRight) ? -value.right : -value.left + case .centerX: + return (value.left - value.right) / 2 + case .centerY: + return (value.top - value.bottom) / 2 case .width: return -(value.left + value.right) case .height: