diff --git a/.swift-version b/.swift-version deleted file mode 100644 index 9f55b2c..0000000 --- a/.swift-version +++ /dev/null @@ -1 +0,0 @@ -3.0 diff --git a/ManualLayout.podspec b/ManualLayout.podspec index 0321d23..3252b3e 100644 --- a/ManualLayout.podspec +++ b/ManualLayout.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'ManualLayout' - s.version = '1.3.0' + s.version = '1.3.1' s.license = { :type => 'MIT', :file => 'LICENSE' } s.summary = 'Easy to use and flexible AutoLayout alternative for iOS 8+. Supports AsyncDisplayKit.' @@ -14,4 +14,5 @@ Pod::Spec.new do |s| s.source_files = 'ManualLayout' s.frameworks = 'UIKit' s.requires_arc = true + s.swift_version = "5.0" end diff --git a/ManualLayout.xcodeproj/project.pbxproj b/ManualLayout.xcodeproj/project.pbxproj index 11b587d..c5d1e34 100644 --- a/ManualLayout.xcodeproj/project.pbxproj +++ b/ManualLayout.xcodeproj/project.pbxproj @@ -386,6 +386,7 @@ developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( + English, en, Base, ); @@ -545,7 +546,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.bsencan.ManualLayout.SimpleExample.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 5.0; }; name = Debug; }; @@ -559,7 +560,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.bsencan.ManualLayout.SimpleExample.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 5.0; }; name = Release; }; @@ -580,7 +581,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.bsencan.ManualLayout.SimpleExample.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 5.0; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/SimpleExample.app/SimpleExample"; }; name = Debug; @@ -599,7 +600,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.bsencan.ManualLayout.SimpleExample.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 5.0; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/SimpleExample.app/SimpleExample"; }; name = Release; @@ -648,6 +649,7 @@ ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; @@ -690,6 +692,7 @@ MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; VERSIONING_SYSTEM = "apple-generic"; @@ -714,7 +717,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 5.0; }; name = Debug; }; @@ -734,7 +737,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.bsencan.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 5.0; }; name = Release; }; @@ -753,7 +756,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.bsencan.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 5.0; }; name = Debug; }; @@ -768,7 +771,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.bsencan.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 5.0; }; name = Release; }; @@ -791,6 +794,7 @@ SDKROOT = appletvos; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = 3; TVOS_DEPLOYMENT_TARGET = 9.0; }; @@ -814,6 +818,7 @@ PRODUCT_NAME = ManualLayout; SDKROOT = appletvos; SKIP_INSTALL = YES; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = 3; TVOS_DEPLOYMENT_TARGET = 9.0; }; diff --git a/ManualLayout/CALayer+ManualLayout.swift b/ManualLayout/CALayer+ManualLayout.swift index f047d2f..ab8023d 100644 --- a/ManualLayout/CALayer+ManualLayout.swift +++ b/ManualLayout/CALayer+ManualLayout.swift @@ -8,116 +8,163 @@ import UIKit -public extension CALayer { +extension CALayer { - // MARK: - Position - - public var origin: CGPoint { - get { - return frame.origin + // MARK: - Position + public var ml_origin: CGPoint { + get { return frame.origin } + set { ml_x = newValue.x; ml_y = newValue.y } } - set { - x = newValue.x - y = newValue.y + public var origin: CGPoint { + get { return ml_origin } + set { ml_origin = newValue } } - } - - public var x: CGFloat { - get { return frame.x } - set { frame.x = newValue } - } - - public var y: CGFloat { - get { return frame.y } - set { frame.y = newValue } - } - - public var center: CGPoint { - get { return frame.center } - set { frame.center = newValue } - } - public var centerX: CGFloat { - get { return frame.centerX } - set { frame.centerX = newValue } - } - - public var centerY: CGFloat { - get { return frame.centerY } - set { frame.centerY = newValue } - } - - // MARK: - Size + public var ml_x: CGFloat { + get { return frame.ml_x } + set { frame.ml_x = newValue } + } + public var x: CGFloat { + get { return ml_x } + set { ml_x = newValue } + } - public var size: CGSize { - get { - return frame.size + public var ml_y: CGFloat { + get { return frame.ml_y } + set { frame.ml_y = newValue } } - set { - width = newValue.width - height = newValue.height + public var y: CGFloat { + get { return ml_y } + set { ml_y = newValue } } - } - public var width: CGFloat { - get { - return frame.size.width + public var ml_center: CGPoint { + get { return frame.ml_center } + set { frame.ml_center = newValue } } - set { - frame.size.width = snapToPixel(pointCoordinate: newValue) + public var center: CGPoint { + get { return ml_center } + set { ml_center = newValue } + } + + public var ml_centerX: CGFloat { + get { return frame.ml_centerX } + set { frame.ml_centerX = newValue } + } + public var centerX: CGFloat { + get { return ml_centerX } + set { ml_centerX = newValue } + } + + public var ml_centerY: CGFloat { + get { return frame.ml_centerY } + set { frame.ml_centerY = newValue } + } + public var centerY: CGFloat { + get { return ml_centerY } + set { ml_centerY = newValue } } - } - public var height: CGFloat { - get { - return frame.size.height + // MARK: - Size + public var ml_size: CGSize { + get { return frame.size } + set { ml_width = newValue.width; ml_height = newValue.height } } - set { - frame.size.height = snapToPixel(pointCoordinate: newValue) + public var size: CGSize { + get { return ml_size } + set { ml_size = newValue } } - } - // MARK: - Edges + public var ml_width: CGFloat { + get { return frame.size.width } + set { frame.size.width = snapToPixel(pointCoordinate: newValue) } + } + public var width: CGFloat { + get { return ml_width } + set { ml_width = newValue } + } - public var top: CGFloat { - get { return frame.top } - set { frame.top = newValue } - } + public var ml_height: CGFloat { + get { return frame.size.height } + set { frame.size.height = snapToPixel(pointCoordinate: newValue) } + } + public var height: CGFloat { + get { return ml_height } + set { ml_height = newValue } + } - public var right: CGFloat { - get { return frame.right } - set { frame.right = newValue } - } + // MARK: - Edges + public var ml_top: CGFloat { + get { return frame.ml_top } + set { frame.ml_top = newValue } + } + public var top: CGFloat { + get { return ml_top } + set { ml_top = newValue } + } - public var bottom: CGFloat { - get { return frame.bottom } - set { frame.bottom = newValue } - } + public var ml_right: CGFloat { + get { return frame.right } + set { frame.right = newValue } + } + public var right: CGFloat { + get { return ml_right } + set { ml_right = newValue } + } - public var left: CGFloat { - get { return frame.left } - set { frame.left = newValue } - } + public var ml_bottom: CGFloat { + get { return frame.bottom } + set { frame.bottom = newValue } + } + public var bottom: CGFloat { + get { return ml_bottom } + set { ml_bottom = newValue } + } - // MARK: - Alternative Edges + public var ml_left: CGFloat { + get { return frame.left } + set { frame.left = newValue } + } + public var left: CGFloat { + get { return ml_left } + set { ml_left = newValue } + } - public var top2: CGFloat { - get { return frame.top2 } - set { frame.top2 = newValue } - } + // MARK: - Alternative Edges + public var ml_top2: CGFloat { + get { return frame.ml_top2 } + set { frame.ml_top2 = newValue } + } + public var top2: CGFloat { + get { return ml_top2 } + set { ml_top2 = newValue } + } - public var right2: CGFloat { - get { return frame.right2 } - set { frame.right2 = newValue } - } + public var ml_right2: CGFloat { + get { return frame.ml_right2 } + set { frame.ml_right2 = newValue } + } + public var right2: CGFloat { + get { return ml_right2 } + set { ml_right2 = newValue } + } - public var bottom2: CGFloat { - get { return frame.bottom2 } - set { frame.bottom2 = newValue } - } + public var ml_bottom2: CGFloat { + get { return frame.ml_bottom2 } + set { frame.ml_bottom2 = newValue } + } + public var bottom2: CGFloat { + get { return ml_bottom2 } + set { ml_bottom2 = newValue } + } - public var left2: CGFloat { - get { return frame.left2 } - set { frame.left2 = newValue } - } + public var ml_left2: CGFloat { + get { return frame.ml_left2 } + set { frame.ml_left2 = newValue } + } + public var left2: CGFloat { + get { return ml_left2 } + set { ml_left2 = newValue } + } + } diff --git a/ManualLayout/CGRect+ManualLayout.swift b/ManualLayout/CGRect+ManualLayout.swift index 059e8f9..1c52d52 100644 --- a/ManualLayout/CGRect+ManualLayout.swift +++ b/ManualLayout/CGRect+ManualLayout.swift @@ -8,159 +8,164 @@ import UIKit -public extension CGRect { - - // MARK: - Position - - public var x: CGFloat { - get { - return origin.x - } - set { - origin.x = snapToPixel(pointCoordinate: newValue) - } - } - - public var y: CGFloat { - get { - return origin.y - } - set { - origin.y = snapToPixel(pointCoordinate: newValue) - } - } - - public var center: CGPoint { - get { - return CGPoint(x: centerX, y: centerY) - } - set { - centerX = newValue.x - centerY = newValue.y - } - } - - public var centerX: CGFloat { - get { - return origin.x + size.width / 2 - } - set { - x = newValue - size.width / 2 - } - } - - public var centerY: CGFloat { - get { - return origin.y + size.height / 2 - } - set { - y = newValue - size.height / 2 - } - } - - // MARK: - Edges - - public var top: CGFloat { - get { - return origin.y - } - set { - y = newValue - } - } - - public var right: CGFloat { - get { - return origin.x + size.width - } - set { - x = newValue - size.width - } - } - - public var bottom: CGFloat { - get { - return origin.y + size.height - } - set { - y = newValue - size.height - } - } - - public var left: CGFloat { - get { - return origin.x - } - set { - x = newValue - } - } - - // MARK: - Alternative Edges - - public var top2: CGFloat { - get { - return origin.y - } - set { - if newValue <= bottom { - size.height += snapToPixel(pointCoordinate: top - newValue) - y = newValue - } else { - // Swap top with bottom. - let newTop = bottom - size.height = snapToPixel(pointCoordinate: newValue - newTop) - y = newTop - } - } - } - - public var right2: CGFloat { - get { - return origin.x + size.width - } - set { - if newValue >= left { - size.width += snapToPixel(pointCoordinate: newValue - right) - } else { - // Swap left with right. - let newRight = left - size.width = snapToPixel(pointCoordinate: newRight - newValue) - x = newValue - } - } - } - - public var bottom2: CGFloat { - get { - return origin.y + size.height - } - set { - if newValue >= top { - size.height += snapToPixel(pointCoordinate: newValue - bottom) - } else { - // Swap bottom with top. - let newBottom = top - size.height = snapToPixel(pointCoordinate: newBottom - newValue) - y = newValue - } - } - } - - public var left2: CGFloat { - get { - return origin.x - } - set { - if newValue <= right { - size.width += snapToPixel(pointCoordinate: left - newValue) - x = newValue - } else { - // Swap right with left. - let newLeft = right - size.width = snapToPixel(pointCoordinate: newValue - newLeft) - x = newLeft - } - } - } +extension CGRect { + + // MARK: - Position + public var ml_x: CGFloat { + get { return origin.x } + set { origin.x = snapToPixel(pointCoordinate: newValue) } + } + public var x: CGFloat { + get { return ml_x } + set { ml_x = newValue } + } + + public var ml_y: CGFloat { + get { return origin.y } + set { origin.y = snapToPixel(pointCoordinate: newValue) } + } + public var y: CGFloat { + get { return ml_y } + set { ml_y = newValue } + } + + public var ml_center: CGPoint { + get { return CGPoint(x: ml_centerX, y: ml_centerY) } + set { ml_centerX = newValue.x; ml_centerY = newValue.y } + } + public var center: CGPoint { + get { return ml_center } + set { ml_center = newValue } + } + + public var ml_centerX: CGFloat { + get { return origin.x + size.width / 2 } + set { ml_x = newValue - size.width / 2 } + } + public var centerX: CGFloat { + get { return ml_centerX } + set { ml_centerX = newValue } + } + + public var ml_centerY: CGFloat { + get { return origin.y + size.height / 2 } + set { ml_y = newValue - size.height / 2 } + } + public var centerY: CGFloat { + get { return ml_centerY } + set { ml_centerY = newValue } + } + + // MARK: - Edges + public var ml_top: CGFloat { + get { return ml_y } + set { ml_y = newValue } + } + public var top: CGFloat { + get { return ml_top } + set { ml_top = newValue } + } + + public var ml_right: CGFloat { + get { return origin.x + size.width } + set { ml_x = newValue - size.width } + } + public var right: CGFloat { + get { return ml_right } + set { ml_right = newValue } + } + + public var ml_bottom: CGFloat { + get { return origin.y + size.height } + set { ml_y = newValue - size.height } + } + public var bottom: CGFloat { + get { return ml_bottom } + set { ml_bottom = newValue } + } + + public var ml_left: CGFloat { + get { return ml_x } + set { ml_x = newValue } + } + public var left: CGFloat { + get { return ml_left } + set { ml_left = newValue } + } + + // MARK: - Alternative Edges + public var ml_top2: CGFloat { + get { return ml_top } + set { + if newValue <= ml_bottom { + size.height += snapToPixel(pointCoordinate: ml_top - newValue) + ml_y = newValue + } else { + // Swap top with bottom. + let newTop = ml_bottom + size.height = snapToPixel(pointCoordinate: newValue - newTop) + ml_y = newTop + } + } + } + public var top2: CGFloat { + get { return ml_top2 } + set { ml_top2 = newValue } + } + + public var ml_right2: CGFloat { + get { return ml_right } + set { + if newValue >= ml_left { + size.width += snapToPixel(pointCoordinate: newValue - ml_right) + } else { + // Swap left with right. + let newRight = ml_left + size.width = snapToPixel(pointCoordinate: newRight - newValue) + ml_x = newValue + } + } + } + public var right2: CGFloat { + get { return ml_right2 } + set { ml_right2 = newValue } + } + + public var ml_bottom2: CGFloat { + get { return ml_bottom } + set { + if newValue >= ml_top { + size.height += snapToPixel(pointCoordinate: newValue - ml_bottom) + } else { + // Swap bottom with top. + let newBottom = ml_top + size.height = snapToPixel(pointCoordinate: newBottom - newValue) + ml_y = newValue + } + } + } + public var bottom2: CGFloat { + get { return ml_bottom2 } + set { ml_bottom2 = newValue } + } + + public var ml_left2: CGFloat { + get { return ml_left } + set { + if newValue <= right { + size.width += snapToPixel(pointCoordinate: left - newValue) + x = newValue + } else { + // Swap right with left. + let newLeft = right + size.width = snapToPixel(pointCoordinate: newValue - newLeft) + x = newLeft + } + } + } + public var left2: CGFloat { + get { return ml_left2 } + set { ml_left2 = newValue } + } + } diff --git a/ManualLayout/UIScrollView+ManualLayout.swift b/ManualLayout/UIScrollView+ManualLayout.swift index 776875a..128d2c6 100644 --- a/ManualLayout/UIScrollView+ManualLayout.swift +++ b/ManualLayout/UIScrollView+ManualLayout.swift @@ -8,91 +8,95 @@ import UIKit -public extension UIScrollView { +extension UIScrollView { - // MARK: - Content Size - - public var contentWidth: CGFloat { - get { - return contentSize.width + // MARK: - Content Size + public var ml_contentWidth: CGFloat { + get { return contentSize.width } + set { contentSize.width = snapToPixel(pointCoordinate: newValue) } } - set { - contentSize.width = snapToPixel(pointCoordinate: newValue) + public var contentWidth: CGFloat { + get { return ml_contentWidth } + set { ml_contentWidth = newValue } } - } - public var contentHeight: CGFloat { - get { - return contentSize.height + public var ml_contentHeight: CGFloat { + get { return contentSize.height } + set { contentSize.height = snapToPixel(pointCoordinate: newValue) } } - set { - contentSize.height = snapToPixel(pointCoordinate: newValue) + public var contentHeight: CGFloat { + get { return ml_contentHeight } + set { ml_contentHeight = newValue } } - } - - // MARK: - Content Edges (For Convenience) - public var contentTop: CGFloat { - return 0 - } - - public var contentLeft: CGFloat { - return 0 - } + // MARK: - Content Edges (For Convenience) + public var ml_contentTop: CGFloat { + return 0 + } + public var contentTop: CGFloat { + return ml_contentTop + } - public var contentBottom: CGFloat { - get { - return contentHeight + public var ml_contentLeft: CGFloat { + return 0 } - set { - contentHeight = newValue + public var contentLeft: CGFloat { + return ml_contentLeft } - } - public var contentRight: CGFloat { - get { - return contentWidth + public var ml_contentBottom: CGFloat { + get { return ml_contentHeight } + set { ml_contentHeight = newValue } } - set { - contentWidth = newValue + public var contentBottom: CGFloat { + get { return ml_contentBottom } + set { ml_contentBottom = newValue } } - } - // MARK: - Viewport Edges + public var ml_contentRight: CGFloat { + get { return ml_contentWidth } + set { ml_contentWidth = newValue } + } + public var contentRight: CGFloat { + get { return ml_contentRight } + set { ml_contentRight = newValue } + } - public var viewportTop: CGFloat { - get { - return contentOffset.y + // MARK: - Viewport Edges + public var ml_viewportTop: CGFloat { + get { return contentOffset.y } + set { contentOffset.y = snapToPixel(pointCoordinate: newValue) } } - set { - contentOffset.y = snapToPixel(pointCoordinate: newValue) + public var viewportTop: CGFloat { + get { return ml_viewportTop } + set { ml_viewportTop = newValue } } - } - public var viewportLeft: CGFloat { - get { - return contentOffset.x + public var ml_viewportLeft: CGFloat { + get { return contentOffset.x } + set { contentOffset.x = snapToPixel(pointCoordinate: newValue) } } - set { - contentOffset.x = snapToPixel(pointCoordinate: newValue) + public var viewportLeft: CGFloat { + get { return ml_viewportLeft } + set { ml_viewportLeft = newValue } } - } - public var viewportBottom: CGFloat { - get { - return contentOffset.y + height + public var ml_viewportBottom: CGFloat { + get { return contentOffset.y + ml_height } + set { contentOffset.y = snapToPixel(pointCoordinate: newValue - ml_height) } } - set { - contentOffset.y = snapToPixel(pointCoordinate: newValue - height) + public var viewportBottom: CGFloat { + get { return ml_viewportBottom } + set { ml_viewportBottom = newValue } } - } - public var viewportRight: CGFloat { - get { - return contentOffset.x + width + public var ml_viewportRight: CGFloat { + get { return contentOffset.x + width } + set { contentOffset.x = snapToPixel(pointCoordinate: newValue - ml_width) } } - set { - contentOffset.x = snapToPixel(pointCoordinate: newValue - width) + public var viewportRight: CGFloat { + get { return ml_viewportRight } + set { ml_viewportRight = newValue } } - } + } diff --git a/ManualLayout/UIView+ManualLayout.swift b/ManualLayout/UIView+ManualLayout.swift index ec293a2..574f574 100644 --- a/ManualLayout/UIView+ManualLayout.swift +++ b/ManualLayout/UIView+ManualLayout.swift @@ -9,109 +9,168 @@ import UIKit // I wish there was an easier way to do this in Swift. -public extension UIView { - - // MARK: - Position - - public var origin: CGPoint { - get { return layer.origin } - set { layer.origin = newValue } - } - - public var x: CGFloat { - get { return layer.x } - set { layer.x = newValue } - } - - public var y: CGFloat { - get { return layer.y } - set { layer.y = newValue } - } - - public var centerX: CGFloat { - get { return layer.centerX } - set { layer.centerX = newValue } - } - - public var centerY: CGFloat { - get { return layer.centerY } - set { layer.centerY = newValue } - } - - // MARK: - Size - - public var size: CGSize { - get { return layer.size } - set { layer.size = newValue } - } - - public var width: CGFloat { - get { return layer.width } - set { layer.width = newValue } - } - - public var height: CGFloat { - get { return layer.height } - set { layer.height = newValue } - } - - // MARK: - Edges - - public var top: CGFloat { - get { return layer.top } - set { layer.top = newValue } - } - - public var right: CGFloat { - get { return layer.right } - set { layer.right = newValue } - } - - public var bottom: CGFloat { - get { return layer.bottom } - set { layer.bottom = newValue } - } - - public var left: CGFloat { - get { return layer.left } - set { layer.left = newValue } - } - - // MARK: - Alternative Edges - - public var top2: CGFloat { - get { return layer.top2 } - set { layer.top2 = newValue } - } - - public var right2: CGFloat { - get { return layer.right2 } - set { layer.right2 = newValue } - } - - public var bottom2: CGFloat { - get { return layer.bottom2 } - set { layer.bottom2 = newValue } - } - - public var left2: CGFloat { - get { return layer.left2 } - set { layer.left2 = newValue } - } - - // MARK: - Automatic Sizing - - @discardableResult - public func sizeToFit(_ width: CGFloat, _ height: CGFloat) -> CGSize { - return sizeToFit(CGSize(width: width, height: height)) - } - - @discardableResult - public func sizeToFit(_ constrainedSize: CGSize) -> CGSize { - var newSize = sizeThatFits(constrainedSize) - newSize.width = min(newSize.width, constrainedSize.width) - newSize.height = min(newSize.height, constrainedSize.height) - size = newSize - return newSize - } +extension UIView { + + // MARK: - Position + public var ml_origin: CGPoint { + get { return layer.ml_origin } + set { layer.ml_origin = newValue } + } + public var origin: CGPoint { + get { return ml_origin } + set { ml_origin = newValue } + } + + public var ml_x: CGFloat { + get { return layer.ml_x } + set { layer.ml_x = newValue } + } + public var x: CGFloat { + get { return ml_x } + set { ml_x = newValue } + } + + public var ml_y: CGFloat { + get { return layer.ml_y } + set { layer.ml_y = newValue } + } + public var y: CGFloat { + get { return ml_y } + set { ml_y = newValue } + } + + public var ml_centerX: CGFloat { + get { return layer.ml_centerX } + set { layer.ml_centerX = newValue } + } + public var centerX: CGFloat { + get { return ml_centerX } + set { ml_centerX = newValue } + } + + public var ml_centerY: CGFloat { + get { return layer.ml_centerY } + set { layer.ml_centerY = newValue } + } + public var centerY: CGFloat { + get { return ml_centerY } + set { ml_centerY = newValue } + } + + // MARK: - Size + public var ml_size: CGSize { + get { return layer.ml_size } + set { layer.ml_size = newValue } + } + public var size: CGSize { + get { return ml_size } + set { ml_size = newValue } + } + + public var ml_width: CGFloat { + get { return layer.ml_width } + set { layer.ml_width = newValue } + } + public var width: CGFloat { + get { return ml_width } + set { ml_width = newValue } + } + + public var ml_height: CGFloat { + get { return layer.ml_height } + set { layer.ml_height = newValue } + } + public var height: CGFloat { + get { return ml_height } + set { ml_height = newValue } + } + + // MARK: - Edges + public var ml_top: CGFloat { + get { return layer.ml_top } + set { layer.ml_top = newValue } + } + public var top: CGFloat { + get { return ml_top } + set { ml_top = newValue } + } + + public var ml_right: CGFloat { + get { return layer.ml_right } + set { layer.ml_right = newValue } + } + public var right: CGFloat { + get { return ml_right } + set { ml_right = newValue } + } + + public var ml_bottom: CGFloat { + get { return layer.ml_bottom } + set { layer.ml_bottom = newValue } + } + public var bottom: CGFloat { + get { return ml_bottom } + set { ml_bottom = newValue } + } + + public var ml_left: CGFloat { + get { return layer.ml_left } + set { layer.ml_left = newValue } + } + public var left: CGFloat { + get { return ml_left } + set { ml_left = newValue } + } + + // MARK: - Alternative Edges + public var ml_top2: CGFloat { + get { return layer.ml_top2 } + set { layer.ml_top2 = newValue } + } + public var top2: CGFloat { + get { return ml_top2 } + set { ml_top2 = newValue } + } + + public var ml_right2: CGFloat { + get { return layer.ml_right2 } + set { layer.ml_right2 = newValue } + } + public var right2: CGFloat { + get { return ml_right2 } + set { ml_right2 = newValue } + } + + public var ml_bottom2: CGFloat { + get { return layer.ml_bottom2 } + set { layer.ml_bottom2 = newValue } + } + public var bottom2: CGFloat { + get { return ml_bottom2 } + set { ml_bottom2 = newValue } + } + + public var ml_left2: CGFloat { + get { return layer.ml_left2 } + set { layer.ml_left2 = newValue } + } + public var left2: CGFloat { + get { return ml_left2 } + set { ml_left2 = newValue } + } + + // MARK: - Automatic Sizing + @discardableResult + public func sizeToFit(_ width: CGFloat, _ height: CGFloat) -> CGSize { + return sizeToFit(CGSize(width: width, height: height)) + } + + @discardableResult + public func sizeToFit(_ constrainedSize: CGSize) -> CGSize { + var newSize = sizeThatFits(constrainedSize) + newSize.width = min(newSize.width, constrainedSize.width) + newSize.height = min(newSize.height, constrainedSize.height) + size = newSize + return newSize + } } diff --git a/ManualLayout/UIViewController+ManualLayout.swift b/ManualLayout/UIViewController+ManualLayout.swift index 7711945..c72893a 100644 --- a/ManualLayout/UIViewController+ManualLayout.swift +++ b/ManualLayout/UIViewController+ManualLayout.swift @@ -8,55 +8,86 @@ import UIKit -public extension UIViewController { - - public var bounds: CGRect { - return view.bounds - } - - // MARK: - Center - - public var center: CGPoint { - return view.center - } - - public var centerX: CGFloat { - return view.centerX - } - - public var centerY: CGFloat { - return view.centerY - } - - // MARK: - Size - - public var size: CGSize { - return view.size - } - - public var width: CGFloat { - return view.width - } - - public var height: CGFloat { - return view.height - } - - // MARK: - Edges - - public var top: CGFloat { - return topLayoutGuide.length - } - - public var right: CGFloat { - return view.width - } - - public var bottom: CGFloat { - return view.height - bottomLayoutGuide.length - } - - public var left: CGFloat { - return 0 - } +extension UIViewController { + + public var ml_bounds: CGRect { + return view.bounds + } + public var bounds: CGRect { + return ml_bounds + } + + // MARK: - Center + public var ml_center: CGPoint { + return view.center + } + public var center: CGPoint { + return ml_center + } + + public var ml_centerX: CGFloat { + return view.ml_centerX + } + public var centerX: CGFloat { + return ml_centerX + } + + public var ml_centerY: CGFloat { + return view.ml_centerY + } + public var centerY: CGFloat { + return ml_centerY + } + + // MARK: - Size + public var ml_size: CGSize { + return view.ml_size + } + public var size: CGSize { + return ml_size + } + + public var ml_width: CGFloat { + return view.ml_width + } + public var width: CGFloat { + return ml_width + } + + public var ml_height: CGFloat { + return view.ml_height + } + public var height: CGFloat { + return ml_height + } + + // MARK: - Edges + public var ml_top: CGFloat { + return topLayoutGuide.length + } + public var top: CGFloat { + return ml_top + } + + public var ml_right: CGFloat { + return view.ml_width + } + public var right: CGFloat { + return ml_right + } + + public var ml_bottom: CGFloat { + return view.ml_height - bottomLayoutGuide.length + } + public var bottom: CGFloat { + return ml_bottom + } + + public var ml_left: CGFloat { + return 0 + } + public var left: CGFloat { + return ml_left + } + }