├── .gitignore ├── Art ├── header.gif ├── header.png └── header.psd ├── Configurations ├── Universal-Framework-Target.xcconfig └── Universal-Target-Base.xcconfig ├── Example ├── Cartfile ├── Cartfile.resolved ├── Podfile ├── TinyConstraints.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ │ └── contents.xcworkspacedata └── TinyConstraints │ ├── Resources │ ├── Base.lproj │ │ └── LaunchScreen.xib │ ├── Images.xcassets │ │ ├── AppIcon.appiconset │ │ │ └── Contents.json │ │ ├── Contents.json │ │ ├── arrow_left.imageset │ │ │ ├── Contents.json │ │ │ ├── arrow_left.png │ │ │ ├── arrow_left@2x.png │ │ │ └── arrow_left@3x.png │ │ └── arrow_right.imageset │ │ │ ├── Contents.json │ │ │ ├── arrow_right.png │ │ │ ├── arrow_right@2x.png │ │ │ └── arrow_right@3x.png │ └── Info.plist │ └── Sources │ ├── AppDelegate.swift │ ├── DemoView.swift │ ├── ExampleViewController.swift │ ├── Extensions.swift │ ├── GradientView.swift │ └── MetricView.swift ├── LICENSE ├── Package.swift ├── README.md ├── TinyConstraints.podspec ├── TinyConstraints.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist └── xcshareddata │ └── xcschemes │ └── TinyConstraints.xcscheme └── TinyConstraints ├── Classes ├── Abstraction.swift ├── Constrainable.swift ├── Constraints.swift ├── Stack.swift ├── TinyConstraints+superview.swift ├── TinyConstraints.swift └── TinyEdgeInsets.swift ├── Info.plist └── TinyConstraints.h /.gitignore: -------------------------------------------------------------------------------- 1 | /TinyConstraints.xcodeproj/xcuserdata 2 | /TinyConstraints.xcodeproj/project.xcworkspace/xcuserdata 3 | /Build 4 | /Example/TinyConstraints.xcodeproj/xcuserdata 5 | /Example/TinyConstraints.xcodeproj/project.xcworkspace/xcuserdata 6 | /Example/Build 7 | .swiftpm 8 | -------------------------------------------------------------------------------- /Art/header.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/roberthein/TinyConstraints/a89996a77d364eb85abdd09d42d2274e35ba56dc/Art/header.gif -------------------------------------------------------------------------------- /Art/header.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/roberthein/TinyConstraints/a89996a77d364eb85abdd09d42d2274e35ba56dc/Art/header.png -------------------------------------------------------------------------------- /Art/header.psd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/roberthein/TinyConstraints/a89996a77d364eb85abdd09d42d2274e35ba56dc/Art/header.psd -------------------------------------------------------------------------------- /Configurations/Universal-Framework-Target.xcconfig: -------------------------------------------------------------------------------- 1 | #include "Universal-Target-Base.xcconfig" 2 | 3 | // macOS-specific default settings 4 | FRAMEWORK_VERSION[sdk=macosx*] = A 5 | COMBINE_HIDPI_IMAGES[sdk=macosx*] = YES 6 | 7 | // iOS-specific default settings 8 | TARGETED_DEVICE_FAMILY[sdk=iphonesimulator*] = 1,2 9 | TARGETED_DEVICE_FAMILY[sdk=iphone*] = 1,2 10 | 11 | // TV-specific default settings 12 | TARGETED_DEVICE_FAMILY[sdk=appletvsimulator*] = 3 13 | TARGETED_DEVICE_FAMILY[sdk=appletv*] = 3 14 | 15 | ENABLE_BITCODE[sdk=macosx*] = NO 16 | ENABLE_BITCODE[sdk=iphonesimulator*] = NO 17 | ENABLE_BITCODE[sdk=iphone*] = YES 18 | ENABLE_BITCODE[sdk=appletvsimulator*] = YES 19 | ENABLE_BITCODE[sdk=appletv*] = YES 20 | -------------------------------------------------------------------------------- /Configurations/Universal-Target-Base.xcconfig: -------------------------------------------------------------------------------- 1 | SUPPORTED_PLATFORMS = macosx iphonesimulator iphoneos appletvos appletvsimulator 2 | VALID_ARCHS[sdk=macosx*] = i386 x86_64 3 | VALID_ARCHS[sdk=iphoneos*] = arm64 armv7 armv7s 4 | VALID_ARCHS[sdk=iphonesimulator*] = i386 x86_64 5 | VALID_ARCHS[sdk=appletv*] = arm64 6 | VALID_ARCHS[sdk=appletvsimulator*] = x86_64 7 | 8 | // Dynamic linking uses different default copy paths 9 | LD_RUNPATH_SEARCH_PATHS[sdk=macosx*] = $(inherited) '@executable_path/../Frameworks' '@loader_path/../Frameworks' 10 | LD_RUNPATH_SEARCH_PATHS[sdk=iphoneos*] = $(inherited) '@executable_path/Frameworks' '@loader_path/Frameworks' 11 | LD_RUNPATH_SEARCH_PATHS[sdk=iphonesimulator*] = $(inherited) '@executable_path/Frameworks' '@loader_path/Frameworks' 12 | LD_RUNPATH_SEARCH_PATHS[sdk=appletvos*] = $(inherited) '@executable_path/Frameworks' '@loader_path/Frameworks' 13 | LD_RUNPATH_SEARCH_PATHS[sdk=appletvsimulator*] = $(inherited) '@executable_path/Frameworks' '@loader_path/Frameworks' 14 | 15 | -------------------------------------------------------------------------------- /Example/Cartfile: -------------------------------------------------------------------------------- 1 | github "roberthein/TinyConstraints" 2 | -------------------------------------------------------------------------------- /Example/Cartfile.resolved: -------------------------------------------------------------------------------- 1 | github "roberthein/TinyConstraints" "4.0.2" 2 | -------------------------------------------------------------------------------- /Example/Podfile: -------------------------------------------------------------------------------- 1 | platform :ios, '12.1' 2 | swift_version = '5.0' 3 | 4 | target 'TinyConstraints_Example' do 5 | pod 'TinyConstraints', :path => '../' 6 | end 7 | -------------------------------------------------------------------------------- /Example/TinyConstraints.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | A91365EB224A44F10060D7C6 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = A91365D8224A44F00060D7C6 /* AppDelegate.swift */; }; 11 | A91365ED224A44F10060D7C6 /* Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = A91365DB224A44F00060D7C6 /* Extensions.swift */; }; 12 | A91365F6224A44F10060D7C6 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = A91365E7224A44F00060D7C6 /* LaunchScreen.xib */; }; 13 | A91365F7224A44F10060D7C6 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A91365E9224A44F00060D7C6 /* Images.xcassets */; }; 14 | A9136603224A4C9E0060D7C6 /* ExampleViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9136600224A4C9E0060D7C6 /* ExampleViewController.swift */; }; 15 | A9136607224A4EB20060D7C6 /* DemoView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9136606224A4EB20060D7C6 /* DemoView.swift */; }; 16 | A913660B224A51290060D7C6 /* MetricView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A913660A224A51290060D7C6 /* MetricView.swift */; }; 17 | A913660D224A85A70060D7C6 /* GradientView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A913660C224A85A70060D7C6 /* GradientView.swift */; }; 18 | /* End PBXBuildFile section */ 19 | 20 | /* Begin PBXCopyFilesBuildPhase section */ 21 | 2DD9871A1E4DC564002F80D6 /* Embed Frameworks */ = { 22 | isa = PBXCopyFilesBuildPhase; 23 | buildActionMask = 2147483647; 24 | dstPath = ""; 25 | dstSubfolderSpec = 10; 26 | files = ( 27 | ); 28 | name = "Embed Frameworks"; 29 | runOnlyForDeploymentPostprocessing = 0; 30 | }; 31 | /* End PBXCopyFilesBuildPhase section */ 32 | 33 | /* Begin PBXFileReference section */ 34 | 047C191FDC846FF0B452C61B /* README.md */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = ""; }; 35 | 56C6ADD413C4A5E217E972AD /* LICENSE */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = LICENSE; path = ../LICENSE; sourceTree = ""; }; 36 | 607FACD01AFB9204008FA782 /* constraints.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = constraints.app; sourceTree = BUILT_PRODUCTS_DIR; }; 37 | 9A367D919D81C2E2930A8B0C /* TinyConstraints.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = TinyConstraints.podspec; path = ../TinyConstraints.podspec; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.ruby; }; 38 | A91365D8224A44F00060D7C6 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 39 | A91365DB224A44F00060D7C6 /* Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Extensions.swift; sourceTree = ""; }; 40 | A91365E8224A44F00060D7C6 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; 41 | A91365E9224A44F00060D7C6 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 42 | A91365EA224A44F00060D7C6 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 43 | A9136600224A4C9E0060D7C6 /* ExampleViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExampleViewController.swift; sourceTree = ""; }; 44 | A9136606224A4EB20060D7C6 /* DemoView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DemoView.swift; sourceTree = ""; }; 45 | A913660A224A51290060D7C6 /* MetricView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MetricView.swift; sourceTree = ""; }; 46 | A913660C224A85A70060D7C6 /* GradientView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GradientView.swift; sourceTree = ""; }; 47 | /* End PBXFileReference section */ 48 | 49 | /* Begin PBXFrameworksBuildPhase section */ 50 | 607FACCD1AFB9204008FA782 /* Frameworks */ = { 51 | isa = PBXFrameworksBuildPhase; 52 | buildActionMask = 2147483647; 53 | files = ( 54 | ); 55 | runOnlyForDeploymentPostprocessing = 0; 56 | }; 57 | /* End PBXFrameworksBuildPhase section */ 58 | 59 | /* Begin PBXGroup section */ 60 | 607FACC71AFB9204008FA782 = { 61 | isa = PBXGroup; 62 | children = ( 63 | 607FACF51AFB993E008FA782 /* Podspec Metadata */, 64 | 607FACD21AFB9204008FA782 /* Example for TinyConstraints */, 65 | 607FACD11AFB9204008FA782 /* Products */, 66 | E4D916F05DC0CB81BD1E78D5 /* Pods */, 67 | ); 68 | sourceTree = ""; 69 | }; 70 | 607FACD11AFB9204008FA782 /* Products */ = { 71 | isa = PBXGroup; 72 | children = ( 73 | 607FACD01AFB9204008FA782 /* constraints.app */, 74 | ); 75 | name = Products; 76 | sourceTree = ""; 77 | }; 78 | 607FACD21AFB9204008FA782 /* Example for TinyConstraints */ = { 79 | isa = PBXGroup; 80 | children = ( 81 | A91365E6224A44F00060D7C6 /* Resources */, 82 | A91365D7224A44F00060D7C6 /* Sources */, 83 | ); 84 | name = "Example for TinyConstraints"; 85 | path = TinyConstraints; 86 | sourceTree = ""; 87 | }; 88 | 607FACF51AFB993E008FA782 /* Podspec Metadata */ = { 89 | isa = PBXGroup; 90 | children = ( 91 | 9A367D919D81C2E2930A8B0C /* TinyConstraints.podspec */, 92 | 047C191FDC846FF0B452C61B /* README.md */, 93 | 56C6ADD413C4A5E217E972AD /* LICENSE */, 94 | ); 95 | name = "Podspec Metadata"; 96 | sourceTree = ""; 97 | }; 98 | A91365D7224A44F00060D7C6 /* Sources */ = { 99 | isa = PBXGroup; 100 | children = ( 101 | A91365DB224A44F00060D7C6 /* Extensions.swift */, 102 | A91365D8224A44F00060D7C6 /* AppDelegate.swift */, 103 | A9136606224A4EB20060D7C6 /* DemoView.swift */, 104 | A9136600224A4C9E0060D7C6 /* ExampleViewController.swift */, 105 | A913660C224A85A70060D7C6 /* GradientView.swift */, 106 | A913660A224A51290060D7C6 /* MetricView.swift */, 107 | ); 108 | path = Sources; 109 | sourceTree = ""; 110 | }; 111 | A91365E6224A44F00060D7C6 /* Resources */ = { 112 | isa = PBXGroup; 113 | children = ( 114 | A91365E7224A44F00060D7C6 /* LaunchScreen.xib */, 115 | A91365E9224A44F00060D7C6 /* Images.xcassets */, 116 | A91365EA224A44F00060D7C6 /* Info.plist */, 117 | ); 118 | path = Resources; 119 | sourceTree = ""; 120 | }; 121 | E4D916F05DC0CB81BD1E78D5 /* Pods */ = { 122 | isa = PBXGroup; 123 | children = ( 124 | ); 125 | path = Pods; 126 | sourceTree = ""; 127 | }; 128 | /* End PBXGroup section */ 129 | 130 | /* Begin PBXNativeTarget section */ 131 | 607FACCF1AFB9204008FA782 /* TinyConstraints_Example */ = { 132 | isa = PBXNativeTarget; 133 | buildConfigurationList = 607FACEF1AFB9204008FA782 /* Build configuration list for PBXNativeTarget "TinyConstraints_Example" */; 134 | buildPhases = ( 135 | 607FACCC1AFB9204008FA782 /* Sources */, 136 | 607FACCD1AFB9204008FA782 /* Frameworks */, 137 | 607FACCE1AFB9204008FA782 /* Resources */, 138 | 2DD9871A1E4DC564002F80D6 /* Embed Frameworks */, 139 | ); 140 | buildRules = ( 141 | ); 142 | dependencies = ( 143 | ); 144 | name = TinyConstraints_Example; 145 | productName = TinyConstraints; 146 | productReference = 607FACD01AFB9204008FA782 /* constraints.app */; 147 | productType = "com.apple.product-type.application"; 148 | }; 149 | /* End PBXNativeTarget section */ 150 | 151 | /* Begin PBXProject section */ 152 | 607FACC81AFB9204008FA782 /* Project object */ = { 153 | isa = PBXProject; 154 | attributes = { 155 | LastSwiftUpdateCheck = 0720; 156 | LastUpgradeCheck = 1020; 157 | ORGANIZATIONNAME = CocoaPods; 158 | TargetAttributes = { 159 | 607FACCF1AFB9204008FA782 = { 160 | CreatedOnToolsVersion = 6.3.1; 161 | DevelopmentTeam = 3TAZ984YN3; 162 | LastSwiftMigration = 1000; 163 | }; 164 | }; 165 | }; 166 | buildConfigurationList = 607FACCB1AFB9204008FA782 /* Build configuration list for PBXProject "TinyConstraints" */; 167 | compatibilityVersion = "Xcode 3.2"; 168 | developmentRegion = English; 169 | hasScannedForEncodings = 0; 170 | knownRegions = ( 171 | English, 172 | en, 173 | Base, 174 | ); 175 | mainGroup = 607FACC71AFB9204008FA782; 176 | productRefGroup = 607FACD11AFB9204008FA782 /* Products */; 177 | projectDirPath = ""; 178 | projectRoot = ""; 179 | targets = ( 180 | 607FACCF1AFB9204008FA782 /* TinyConstraints_Example */, 181 | ); 182 | }; 183 | /* End PBXProject section */ 184 | 185 | /* Begin PBXResourcesBuildPhase section */ 186 | 607FACCE1AFB9204008FA782 /* Resources */ = { 187 | isa = PBXResourcesBuildPhase; 188 | buildActionMask = 2147483647; 189 | files = ( 190 | A91365F6224A44F10060D7C6 /* LaunchScreen.xib in Resources */, 191 | A91365F7224A44F10060D7C6 /* Images.xcassets in Resources */, 192 | ); 193 | runOnlyForDeploymentPostprocessing = 0; 194 | }; 195 | /* End PBXResourcesBuildPhase section */ 196 | 197 | /* Begin PBXSourcesBuildPhase section */ 198 | 607FACCC1AFB9204008FA782 /* Sources */ = { 199 | isa = PBXSourcesBuildPhase; 200 | buildActionMask = 2147483647; 201 | files = ( 202 | A9136603224A4C9E0060D7C6 /* ExampleViewController.swift in Sources */, 203 | A91365ED224A44F10060D7C6 /* Extensions.swift in Sources */, 204 | A91365EB224A44F10060D7C6 /* AppDelegate.swift in Sources */, 205 | A913660D224A85A70060D7C6 /* GradientView.swift in Sources */, 206 | A9136607224A4EB20060D7C6 /* DemoView.swift in Sources */, 207 | A913660B224A51290060D7C6 /* MetricView.swift in Sources */, 208 | ); 209 | runOnlyForDeploymentPostprocessing = 0; 210 | }; 211 | /* End PBXSourcesBuildPhase section */ 212 | 213 | /* Begin PBXVariantGroup section */ 214 | A91365E7224A44F00060D7C6 /* LaunchScreen.xib */ = { 215 | isa = PBXVariantGroup; 216 | children = ( 217 | A91365E8224A44F00060D7C6 /* Base */, 218 | ); 219 | name = LaunchScreen.xib; 220 | sourceTree = ""; 221 | }; 222 | /* End PBXVariantGroup section */ 223 | 224 | /* Begin XCBuildConfiguration section */ 225 | 607FACED1AFB9204008FA782 /* Debug */ = { 226 | isa = XCBuildConfiguration; 227 | buildSettings = { 228 | ALWAYS_SEARCH_USER_PATHS = NO; 229 | CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; 230 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 231 | CLANG_CXX_LIBRARY = "libc++"; 232 | CLANG_ENABLE_MODULES = YES; 233 | CLANG_ENABLE_OBJC_ARC = YES; 234 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 235 | CLANG_WARN_BOOL_CONVERSION = YES; 236 | CLANG_WARN_COMMA = YES; 237 | CLANG_WARN_CONSTANT_CONVERSION = YES; 238 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 239 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 240 | CLANG_WARN_EMPTY_BODY = YES; 241 | CLANG_WARN_ENUM_CONVERSION = YES; 242 | CLANG_WARN_INFINITE_RECURSION = YES; 243 | CLANG_WARN_INT_CONVERSION = YES; 244 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 245 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 246 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 247 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 248 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 249 | CLANG_WARN_STRICT_PROTOTYPES = YES; 250 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 251 | CLANG_WARN_UNREACHABLE_CODE = YES; 252 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 253 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 254 | COPY_PHASE_STRIP = NO; 255 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 256 | ENABLE_STRICT_OBJC_MSGSEND = YES; 257 | ENABLE_TESTABILITY = YES; 258 | GCC_C_LANGUAGE_STANDARD = gnu99; 259 | GCC_DYNAMIC_NO_PIC = NO; 260 | GCC_NO_COMMON_BLOCKS = YES; 261 | GCC_OPTIMIZATION_LEVEL = 0; 262 | GCC_PREPROCESSOR_DEFINITIONS = ( 263 | "DEBUG=1", 264 | "$(inherited)", 265 | ); 266 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 267 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 268 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 269 | GCC_WARN_UNDECLARED_SELECTOR = YES; 270 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 271 | GCC_WARN_UNUSED_FUNCTION = YES; 272 | GCC_WARN_UNUSED_VARIABLE = YES; 273 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 274 | MTL_ENABLE_DEBUG_INFO = YES; 275 | ONLY_ACTIVE_ARCH = YES; 276 | SDKROOT = iphoneos; 277 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 278 | SWIFT_VERSION = 5.0; 279 | }; 280 | name = Debug; 281 | }; 282 | 607FACEE1AFB9204008FA782 /* Release */ = { 283 | isa = XCBuildConfiguration; 284 | buildSettings = { 285 | ALWAYS_SEARCH_USER_PATHS = NO; 286 | CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; 287 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 288 | CLANG_CXX_LIBRARY = "libc++"; 289 | CLANG_ENABLE_MODULES = YES; 290 | CLANG_ENABLE_OBJC_ARC = YES; 291 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 292 | CLANG_WARN_BOOL_CONVERSION = YES; 293 | CLANG_WARN_COMMA = YES; 294 | CLANG_WARN_CONSTANT_CONVERSION = YES; 295 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 296 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 297 | CLANG_WARN_EMPTY_BODY = YES; 298 | CLANG_WARN_ENUM_CONVERSION = YES; 299 | CLANG_WARN_INFINITE_RECURSION = YES; 300 | CLANG_WARN_INT_CONVERSION = YES; 301 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 302 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 303 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 304 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 305 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 306 | CLANG_WARN_STRICT_PROTOTYPES = YES; 307 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 308 | CLANG_WARN_UNREACHABLE_CODE = YES; 309 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 310 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 311 | COPY_PHASE_STRIP = NO; 312 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 313 | ENABLE_NS_ASSERTIONS = NO; 314 | ENABLE_STRICT_OBJC_MSGSEND = YES; 315 | GCC_C_LANGUAGE_STANDARD = gnu99; 316 | GCC_NO_COMMON_BLOCKS = YES; 317 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 318 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 319 | GCC_WARN_UNDECLARED_SELECTOR = YES; 320 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 321 | GCC_WARN_UNUSED_FUNCTION = YES; 322 | GCC_WARN_UNUSED_VARIABLE = YES; 323 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 324 | MTL_ENABLE_DEBUG_INFO = NO; 325 | SDKROOT = iphoneos; 326 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 327 | SWIFT_VERSION = 5.0; 328 | VALIDATE_PRODUCT = YES; 329 | }; 330 | name = Release; 331 | }; 332 | 607FACF01AFB9204008FA782 /* Debug */ = { 333 | isa = XCBuildConfiguration; 334 | buildSettings = { 335 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = "$(inherited)"; 336 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 337 | DEVELOPMENT_TEAM = 3TAZ984YN3; 338 | INFOPLIST_FILE = TinyConstraints/Resources/Info.plist; 339 | IPHONEOS_DEPLOYMENT_TARGET = 11.0; 340 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 341 | MODULE_NAME = ExampleApp; 342 | PRODUCT_BUNDLE_IDENTIFIER = no.tc.test; 343 | PRODUCT_NAME = constraints; 344 | SWIFT_VERSION = 5.0; 345 | TARGETED_DEVICE_FAMILY = "1,2"; 346 | }; 347 | name = Debug; 348 | }; 349 | 607FACF11AFB9204008FA782 /* Release */ = { 350 | isa = XCBuildConfiguration; 351 | buildSettings = { 352 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = "$(inherited)"; 353 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 354 | DEVELOPMENT_TEAM = 3TAZ984YN3; 355 | INFOPLIST_FILE = TinyConstraints/Resources/Info.plist; 356 | IPHONEOS_DEPLOYMENT_TARGET = 11.0; 357 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 358 | MODULE_NAME = ExampleApp; 359 | PRODUCT_BUNDLE_IDENTIFIER = no.tc.test; 360 | PRODUCT_NAME = constraints; 361 | SWIFT_VERSION = 5.0; 362 | TARGETED_DEVICE_FAMILY = "1,2"; 363 | }; 364 | name = Release; 365 | }; 366 | /* End XCBuildConfiguration section */ 367 | 368 | /* Begin XCConfigurationList section */ 369 | 607FACCB1AFB9204008FA782 /* Build configuration list for PBXProject "TinyConstraints" */ = { 370 | isa = XCConfigurationList; 371 | buildConfigurations = ( 372 | 607FACED1AFB9204008FA782 /* Debug */, 373 | 607FACEE1AFB9204008FA782 /* Release */, 374 | ); 375 | defaultConfigurationIsVisible = 0; 376 | defaultConfigurationName = Release; 377 | }; 378 | 607FACEF1AFB9204008FA782 /* Build configuration list for PBXNativeTarget "TinyConstraints_Example" */ = { 379 | isa = XCConfigurationList; 380 | buildConfigurations = ( 381 | 607FACF01AFB9204008FA782 /* Debug */, 382 | 607FACF11AFB9204008FA782 /* Release */, 383 | ); 384 | defaultConfigurationIsVisible = 0; 385 | defaultConfigurationName = Release; 386 | }; 387 | /* End XCConfigurationList section */ 388 | }; 389 | rootObject = 607FACC81AFB9204008FA782 /* Project object */; 390 | } 391 | -------------------------------------------------------------------------------- /Example/TinyConstraints.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Example/TinyConstraints/Resources/Base.lproj/LaunchScreen.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /Example/TinyConstraints/Resources/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "20x20", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "20x20", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "29x29", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "29x29", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "40x40", 66 | "scale" : "1x" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "size" : "40x40", 71 | "scale" : "2x" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "size" : "76x76", 76 | "scale" : "1x" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "size" : "76x76", 81 | "scale" : "2x" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "size" : "83.5x83.5", 86 | "scale" : "2x" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "size" : "1024x1024", 91 | "scale" : "1x" 92 | } 93 | ], 94 | "info" : { 95 | "version" : 1, 96 | "author" : "xcode" 97 | } 98 | } -------------------------------------------------------------------------------- /Example/TinyConstraints/Resources/Images.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /Example/TinyConstraints/Resources/Images.xcassets/arrow_left.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "arrow_left.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "filename" : "arrow_left@2x.png", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "universal", 15 | "filename" : "arrow_left@3x.png", 16 | "scale" : "3x" 17 | } 18 | ], 19 | "info" : { 20 | "version" : 1, 21 | "author" : "xcode" 22 | } 23 | } -------------------------------------------------------------------------------- /Example/TinyConstraints/Resources/Images.xcassets/arrow_left.imageset/arrow_left.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/roberthein/TinyConstraints/a89996a77d364eb85abdd09d42d2274e35ba56dc/Example/TinyConstraints/Resources/Images.xcassets/arrow_left.imageset/arrow_left.png -------------------------------------------------------------------------------- /Example/TinyConstraints/Resources/Images.xcassets/arrow_left.imageset/arrow_left@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/roberthein/TinyConstraints/a89996a77d364eb85abdd09d42d2274e35ba56dc/Example/TinyConstraints/Resources/Images.xcassets/arrow_left.imageset/arrow_left@2x.png -------------------------------------------------------------------------------- /Example/TinyConstraints/Resources/Images.xcassets/arrow_left.imageset/arrow_left@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/roberthein/TinyConstraints/a89996a77d364eb85abdd09d42d2274e35ba56dc/Example/TinyConstraints/Resources/Images.xcassets/arrow_left.imageset/arrow_left@3x.png -------------------------------------------------------------------------------- /Example/TinyConstraints/Resources/Images.xcassets/arrow_right.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "arrow_right.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "filename" : "arrow_right@2x.png", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "universal", 15 | "filename" : "arrow_right@3x.png", 16 | "scale" : "3x" 17 | } 18 | ], 19 | "info" : { 20 | "version" : 1, 21 | "author" : "xcode" 22 | } 23 | } -------------------------------------------------------------------------------- /Example/TinyConstraints/Resources/Images.xcassets/arrow_right.imageset/arrow_right.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/roberthein/TinyConstraints/a89996a77d364eb85abdd09d42d2274e35ba56dc/Example/TinyConstraints/Resources/Images.xcassets/arrow_right.imageset/arrow_right.png -------------------------------------------------------------------------------- /Example/TinyConstraints/Resources/Images.xcassets/arrow_right.imageset/arrow_right@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/roberthein/TinyConstraints/a89996a77d364eb85abdd09d42d2274e35ba56dc/Example/TinyConstraints/Resources/Images.xcassets/arrow_right.imageset/arrow_right@2x.png -------------------------------------------------------------------------------- /Example/TinyConstraints/Resources/Images.xcassets/arrow_right.imageset/arrow_right@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/roberthein/TinyConstraints/a89996a77d364eb85abdd09d42d2274e35ba56dc/Example/TinyConstraints/Resources/Images.xcassets/arrow_right.imageset/arrow_right@3x.png -------------------------------------------------------------------------------- /Example/TinyConstraints/Resources/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationPortraitUpsideDown 35 | UIInterfaceOrientationLandscapeLeft 36 | UIInterfaceOrientationLandscapeRight 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /Example/TinyConstraints/Sources/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | import UIKit 3 | 4 | @UIApplicationMain 5 | class AppDelegate: UIResponder, UIApplicationDelegate { 6 | 7 | var window: UIWindow? 8 | 9 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool { 10 | 11 | let viewController = ExampleViewController() 12 | viewController.title = "TinyConstraints" 13 | 14 | let navigationController = UINavigationController(rootViewController: viewController) 15 | navigationController.navigationBar.prefersLargeTitles = true 16 | 17 | window = UIWindow(frame: UIScreen.main.bounds) 18 | window?.rootViewController = navigationController 19 | window?.makeKeyAndVisible() 20 | 21 | return true 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Example/TinyConstraints/Sources/DemoView.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | import UIKit 3 | import TinyConstraints 4 | 5 | class DemoView: GradientView { 6 | 7 | lazy var displayLink = CADisplayLink(target: self, selector: #selector(update(_:))) 8 | 9 | lazy var widthMetricView = MetricView() 10 | 11 | lazy var overlay: UIView = { 12 | let view = UIView() 13 | view.backgroundColor = UIColor.white.withAlphaComponent(0.3) 14 | view.clipsToBounds = true 15 | view.layer.cornerRadius = 4 16 | 17 | return view 18 | }() 19 | 20 | required init() { 21 | super.init(frame: .zero) 22 | 23 | locations = [0, 1] 24 | colors = [.tinyBlue, .tinyBlue] 25 | widthMetricView.arrowColor = .white 26 | 27 | clipsToBounds = true 28 | layer.cornerRadius = 5 29 | 30 | addSubview(overlay) 31 | addSubview(widthMetricView) 32 | 33 | overlay.edgesToSuperview(insets: .uniform(3)) 34 | 35 | widthMetricView.leftToSuperview() 36 | widthMetricView.rightToSuperview() 37 | widthMetricView.centerYToSuperview() 38 | } 39 | 40 | override func didMoveToSuperview() { 41 | super.didMoveToSuperview() 42 | 43 | displayLink.add(to: .current, forMode: .common) 44 | } 45 | 46 | required init?(coder aDecoder: NSCoder) { 47 | fatalError("init(coder:) has not been implemented") 48 | } 49 | 50 | @objc func update(_ displayLink: CADisplayLink) { 51 | let presentation = layer.presentation()! 52 | 53 | widthMetricView.label.text = .valueString(for: presentation.frame.width) 54 | 55 | let layoutMargin: CGFloat = 20 56 | 57 | let safeArea = superview!.safeAreaInsets 58 | let leftPosition = layoutMargin + safeArea.left 59 | let rightPosition = UIScreen.main.bounds.width - ((layoutMargin * 2) + safeArea.left + safeArea.right) 60 | 61 | colors = [ 62 | .blend(ratio: presentation.frame.minX.map(from: leftPosition ... rightPosition, to: 0 ... 1)), 63 | .blend(ratio: presentation.frame.maxX.map(from: leftPosition ... rightPosition, to: 0 ... 1)) 64 | ] 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /Example/TinyConstraints/Sources/ExampleViewController.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | import UIKit 3 | import TinyConstraints 4 | 5 | class ExampleViewController: UIViewController { 6 | 7 | enum LinearType: CaseIterable { 8 | case horizontal 9 | case vertical 10 | case recursive 11 | } 12 | 13 | var type: LinearType = .horizontal { 14 | didSet { 15 | [verticalConstraints, 16 | horizontalConstraints, 17 | recursiveConstraints].compactMap { $0 }.forEach { $0.deActivate() } 18 | 19 | switch type { 20 | case .horizontal: 21 | horizontalConstraints?.activate() 22 | case .vertical: 23 | verticalConstraints?.activate() 24 | case .recursive: 25 | recursiveConstraints?.activate() 26 | } 27 | UIView.animate(withDuration: 1.2, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 0, options: [.curveEaseInOut, .beginFromCurrentState], animations: { 28 | self.view.layoutIfNeeded() 29 | }, completion: nil) 30 | } 31 | } 32 | 33 | let layoutMargin: CGFloat = 20 34 | lazy var layoutGuide = UILayoutGuide() 35 | 36 | lazy var demoView1 = DemoView() 37 | lazy var demoView2 = DemoView() 38 | lazy var demoView3 = DemoView() 39 | lazy var demoView4 = DemoView() 40 | 41 | var demoViews: [DemoView] { 42 | return [ 43 | demoView1, 44 | demoView2, 45 | demoView3, 46 | demoView4, 47 | ] 48 | } 49 | 50 | var horizontalConstraints: [Constraint]? 51 | var verticalConstraints: [Constraint]? 52 | var recursiveConstraints: [Constraint]? 53 | 54 | override func viewDidLoad() { 55 | super.viewDidLoad() 56 | 57 | view.backgroundColor = .white 58 | view.addLayoutGuide(layoutGuide) 59 | 60 | demoViews.forEach { demoView in 61 | view.addSubview(demoView) 62 | } 63 | 64 | horizontalConstraints = createHorizontalConstraints() 65 | horizontalConstraints?.activate() 66 | verticalConstraints = createVerticalConstraints() 67 | recursiveConstraints = createRecursiveConstraints() 68 | 69 | Timer.scheduledTimer(withTimeInterval: 3, repeats: true) { _ in 70 | self.type = self.type.next() 71 | } 72 | } 73 | 74 | func createHorizontalConstraints() -> Constraints { 75 | var constraints = Constraints() 76 | var previous: Constrainable = layoutGuide 77 | let offset: CGFloat = 4 78 | 79 | constraints.append(layoutGuide.left(to: view.safeAreaLayoutGuide, offset: layoutMargin, isActive: false)) 80 | constraints.append(layoutGuide.right(to: view.safeAreaLayoutGuide, offset: -layoutMargin, isActive: false)) 81 | constraints.append(layoutGuide.centerY(to: view.safeAreaLayoutGuide, isActive: false)) 82 | 83 | demoViews.enumerated().forEach { i, demoView in 84 | if i == 0 { 85 | constraints.append(demoView.left(to: previous, isActive: false)) 86 | } else { 87 | constraints.append(demoView.leftToRight(of: previous, offset: offset, isActive: false)) 88 | constraints.append(demoView.width(to: previous, isActive: false)) 89 | } 90 | 91 | constraints.append(demoView.top(to: layoutGuide, isActive: false)) 92 | constraints.append(demoView.bottom(to: layoutGuide, isActive: false)) 93 | constraints.append(demoView.heightToWidth(of: demoView, isActive: false)) 94 | 95 | if i == demoViews.count - 1 { 96 | constraints.append(demoView.right(to: layoutGuide, isActive: false)) 97 | } 98 | 99 | previous = demoView 100 | } 101 | 102 | return constraints 103 | } 104 | 105 | func createVerticalConstraints() -> Constraints { 106 | let width: CGFloat = 75 107 | let offset: CGFloat = 4 108 | 109 | var constraints: Constraints = [ 110 | demoView1.topToBottom(of: demoView2, offset: offset, isActive: false), 111 | demoView1.left(to: layoutGuide, isActive: false), 112 | demoView1.bottom(to: layoutGuide, isActive: false), 113 | demoView1.width(width, isActive: false), 114 | 115 | demoView2.top(to: layoutGuide, isActive: false), 116 | demoView2.left(to: layoutGuide, isActive: false), 117 | demoView2.rightToLeft(of: demoView4, offset: -offset, isActive: false), 118 | demoView2.height(width, isActive: false), 119 | 120 | demoView3.leftToRight(of: demoView1, offset: offset, isActive: false), 121 | demoView3.height(width, isActive: false), 122 | demoView3.bottom(to: layoutGuide, isActive: false), 123 | demoView3.right(to: layoutGuide, isActive: false), 124 | 125 | demoView4.top(to: layoutGuide, isActive: false), 126 | demoView4.right(to: layoutGuide, isActive: false), 127 | demoView4.width(width, isActive: false), 128 | demoView4.bottomToTop(of: demoView3, offset: -offset, isActive: false) 129 | ] 130 | 131 | constraints.append(contentsOf: layoutGuide.edges(to: view.safeAreaLayoutGuide, insets: .uniform(layoutMargin), isActive: false)) 132 | 133 | return constraints 134 | } 135 | 136 | func createRecursiveConstraints() -> Constraints { 137 | var constraints = Constraints() 138 | 139 | constraints.append(contentsOf: demoView1.edgesToSuperview(insets: .uniform(layoutMargin), isActive: false, usingSafeArea: true)) 140 | 141 | constraints.append(contentsOf: demoView2.origin(to: demoView1, insets: .top(layoutMargin) + .left(layoutMargin), isActive: false)) 142 | constraints.append(contentsOf: demoView2.size(to: demoView1, multiplier: 0.5, insets: CGSize(width: -layoutMargin * 1.5, height: -layoutMargin * 2), isActive: false)) 143 | 144 | constraints.append(demoView4.top(to: demoView1, offset: layoutMargin, isActive: false)) 145 | constraints.append(demoView4.right(to: demoView1, offset: -layoutMargin, isActive: false)) 146 | constraints.append(contentsOf: demoView4.size(to: demoView2)) 147 | 148 | constraints.append(contentsOf: demoView3.edges(to: demoView1, excluding: .top, insets: .uniform(layoutMargin), isActive: false)) 149 | constraints.append(demoView3.height(to: demoView1, multiplier: 0.5, offset: -layoutMargin * 2, isActive: false)) 150 | 151 | return constraints 152 | } 153 | 154 | override var prefersHomeIndicatorAutoHidden: Bool { 155 | return false 156 | } 157 | } 158 | -------------------------------------------------------------------------------- /Example/TinyConstraints/Sources/Extensions.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | import UIKit 3 | 4 | extension String { 5 | 6 | static func valueString(for value: CGFloat) -> String { 7 | return String(format: "%.0f", ceil(value)) 8 | } 9 | } 10 | 11 | public extension UIColor { 12 | 13 | static func rgb(_ r: CGFloat, _ g: CGFloat, _ b: CGFloat) -> UIColor { 14 | return UIColor(red: r/255, green: g/255, blue: b/255, alpha: 1) 15 | } 16 | 17 | class var tinyBlue: UIColor { 18 | return .rgb(1, 120, 255) 19 | } 20 | 21 | class var tinyGreen: UIColor { 22 | return .rgb(1, 246, 187) 23 | } 24 | 25 | class func blend(ratio: CGFloat) -> UIColor { 26 | let first: UIColor = .tinyBlue 27 | let second: UIColor = .tinyGreen 28 | 29 | func blendComponent(from firstValue: CGFloat, to secondValue: CGFloat) -> CGFloat { 30 | let diff = secondValue - firstValue 31 | return diff * ratio + firstValue 32 | } 33 | 34 | let firstCIColor = CIColor(color: first) 35 | let secondCIColor = CIColor(color: second) 36 | 37 | let red = blendComponent(from: firstCIColor.red, to: secondCIColor.red) 38 | let green = blendComponent(from: firstCIColor.green, to: secondCIColor.green) 39 | let blue = blendComponent(from: firstCIColor.blue, to: secondCIColor.blue) 40 | let alpha = blendComponent(from: firstCIColor.alpha, to: secondCIColor.alpha) 41 | 42 | return UIColor(red: red, green: green, blue: blue, alpha: alpha) 43 | } 44 | } 45 | 46 | public extension CGFloat { 47 | 48 | func map(from: ClosedRange, to: ClosedRange) -> CGFloat { 49 | return ((self - from.lowerBound) / (from.upperBound - from.lowerBound)) * (to.upperBound - to.lowerBound) + to.lowerBound 50 | } 51 | } 52 | 53 | public extension CaseIterable where Self: Equatable { 54 | 55 | func next() -> Self { 56 | let all = Self.allCases 57 | let idx = all.firstIndex(of: self)! 58 | let next = all.index(after: idx) 59 | return all[next == all.endIndex ? all.startIndex : next] 60 | } 61 | } 62 | 63 | extension CALayer { 64 | 65 | func drawLine(from start: CGPoint, to end: CGPoint, color: UIColor, dashed: Bool = false) { 66 | let path = UIBezierPath() 67 | path.move(to: start) 68 | path.addLine(to: end) 69 | 70 | let line = CAShapeLayer() 71 | line.path = path.cgPath 72 | line.fillColor = nil 73 | line.strokeColor = color.cgColor 74 | line.lineCap = .round 75 | line.lineJoin = .round 76 | line.lineWidth = 4 77 | 78 | if dashed { 79 | line.lineDashPattern = [0, 10] 80 | } 81 | 82 | addSublayer(line) 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /Example/TinyConstraints/Sources/GradientView.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | 3 | class GradientView: UIView { 4 | 5 | open var colors: [UIColor]? { 6 | didSet { 7 | updateGradient() 8 | } 9 | } 10 | 11 | open var locations: [CGFloat]? { 12 | didSet { 13 | updateGradient() 14 | } 15 | } 16 | 17 | override open func draw(_ rect: CGRect) { 18 | let context = UIGraphicsGetCurrentContext() 19 | let size = bounds.size 20 | 21 | if let gradient = gradient { 22 | let options: CGGradientDrawingOptions = [.drawsAfterEndLocation] 23 | 24 | let startPoint = CGPoint.zero 25 | let endPoint = CGPoint(x: size.width, y: 0) 26 | context?.drawLinearGradient(gradient, start: startPoint, end: endPoint, options: options) 27 | } 28 | } 29 | 30 | override open func didMoveToWindow() { 31 | super.didMoveToWindow() 32 | contentMode = .redraw 33 | } 34 | 35 | fileprivate var gradient: CGGradient? 36 | 37 | fileprivate func updateGradient() { 38 | gradient = nil 39 | setNeedsDisplay() 40 | 41 | if let colors = colors { 42 | let colorSpace = CGColorSpaceCreateDeviceRGB() 43 | let colorSpaceModel = colorSpace.model 44 | 45 | let gradientColors = colors.map { (color: UIColor) -> AnyObject in 46 | let cgColor = color.cgColor 47 | let cgColorSpace = cgColor.colorSpace ?? colorSpace 48 | 49 | if cgColorSpace.model == colorSpaceModel { 50 | return cgColor as AnyObject 51 | } 52 | 53 | var red: CGFloat = 0 54 | var blue: CGFloat = 0 55 | var green: CGFloat = 0 56 | var alpha: CGFloat = 0 57 | color.getRed(&red, green: &green, blue: &blue, alpha: &alpha) 58 | return UIColor(red: red, green: green, blue: blue, alpha: alpha).cgColor as AnyObject 59 | } as NSArray 60 | 61 | gradient = CGGradient(colorsSpace: colorSpace, colors: gradientColors, locations: locations) 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /Example/TinyConstraints/Sources/MetricView.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | import UIKit 3 | import TinyConstraints 4 | 5 | class MetricView: UIView { 6 | 7 | var arrowColor: UIColor = .white { 8 | didSet { 9 | subviews.forEach { 10 | $0.tintColor = arrowColor 11 | $0.layer.sublayers?.compactMap { $0 as? CAShapeLayer }.forEach { 12 | $0.strokeColor = arrowColor.cgColor 13 | } 14 | } 15 | label.textColor = arrowColor 16 | setNeedsDisplay() 17 | } 18 | } 19 | 20 | lazy var label: UILabel = { 21 | let view = UILabel() 22 | view.textColor = arrowColor 23 | view.font = UIFont.systemFont(ofSize: 20, weight: .bold) 24 | 25 | return view 26 | }() 27 | 28 | let imageSize = CGSize(width: 8, height: 10) 29 | 30 | required init() { 31 | super.init(frame: .zero) 32 | 33 | let rightArrow = UIImageView(image: UIImage(named: "arrow_right")?.withRenderingMode(.alwaysTemplate)) 34 | rightArrow.tintColor = arrowColor 35 | 36 | let leftArrow = UIImageView(image: UIImage(named: "arrow_left")?.withRenderingMode(.alwaysTemplate)) 37 | leftArrow.tintColor = arrowColor 38 | 39 | let lineLeft = UIView() 40 | lineLeft.layer.drawLine(from: CGPoint(x: 0, y: imageSize.height / 2), to: CGPoint(x: 2000, y: imageSize.height / 2), color: arrowColor, dashed: true) 41 | lineLeft.clipsToBounds = true 42 | 43 | let lineRight = UIView() 44 | lineRight.layer.drawLine(from: CGPoint(x: 0, y: imageSize.height / 2), to: CGPoint(x: 2000, y: imageSize.height / 2), color: arrowColor, dashed: true) 45 | lineRight.clipsToBounds = true 46 | 47 | addSubview(rightArrow) 48 | addSubview(leftArrow) 49 | 50 | addSubview(lineLeft) 51 | addSubview(lineRight) 52 | addSubview(label) 53 | 54 | rightArrow.size(imageSize) 55 | rightArrow.rightToSuperview(offset: -2) 56 | rightArrow.centerYToSuperview() 57 | 58 | leftArrow.size(imageSize) 59 | leftArrow.leftToSuperview(offset: 2) 60 | leftArrow.centerYToSuperview() 61 | 62 | lineLeft.leftToRight(of: leftArrow) 63 | lineLeft.rightToLeft(of: label, offset: -2) 64 | lineLeft.height(imageSize.height) 65 | lineLeft.centerYToSuperview() 66 | 67 | lineRight.leftToRight(of: label, offset: 2) 68 | lineRight.rightToLeft(of: rightArrow) 69 | lineRight.height(imageSize.height) 70 | lineRight.centerYToSuperview() 71 | 72 | label.topToSuperview() 73 | label.bottomToSuperview() 74 | label.centerXToSuperview() 75 | } 76 | 77 | required init?(coder aDecoder: NSCoder) { 78 | fatalError("init(coder:) has not been implemented") 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | MIT License 3 | 4 | Copyright (c) 2017 Robert-Hein Hooijmans 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version:5.0 2 | import PackageDescription 3 | 4 | let package = Package( 5 | name: "TinyConstraints", 6 | platforms: [ 7 | .macOS(.v10_11), .iOS(.v9), .tvOS(.v9) 8 | ], 9 | products: [ 10 | .library(name: "TinyConstraints", targets: ["TinyConstraints"]) 11 | ], 12 | targets: [ 13 | .target( 14 | name: "TinyConstraints", 15 | path: "TinyConstraints" 16 | ) 17 | ], 18 | swiftLanguageVersions: [.v5] 19 | ) 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | **TinyConstraints** is the syntactic sugar that makes Auto Layout sweeter for human use. 2 | 3 |

4 | TinyConstraints 5 |

6 | 7 | ## Features 8 | 9 | - [X] Pure Swift 5 sweetness. 10 | - [X] Everything you can do with Auto Layout, but shorter. 11 | - [X] Constraints are active by default. 12 | - [X] 100% compatible with other Auto Layout code. 13 | - [X] Optionally store your constraints. 14 | - [X] Set constraint priorities upon creation. 15 | - [X] Constrain directly to the superview. 16 | - [X] Stack views together with one line of code. 17 | - [X] No need to set `translatesAutoresizingMaskIntoConstraints` because `TinyConstraints` does it for you. 18 | 19 | ## Examples 20 | ### Edges 21 | Attaching a view to its superview with `NSLayoutConstraint`: 22 | 23 | ```swift 24 | NSLayoutConstraint.activate([ 25 | view.topAnchor.constraint(equalTo: superview.topAnchor, constant: 0), 26 | view.leadingAnchor.constraint(equalTo: superview.leadingAnchor, constant: 0), 27 | view.bottomAnchor.constraint(equalTo: superview.bottomAnchor, constant: 0), 28 | view.trailingAnchor.constraint(equalTo: superview.trailingAnchor, constant: 0) 29 | ]) 30 | ``` 31 | 32 | with `TinyConstraints`: 33 | 34 | ```swift 35 | view.edgesToSuperview() 36 | ``` 37 | 38 | or: 39 | 40 | ```swift 41 | view.edgesToSuperview(insets: .top(10) + .left(10)) 42 | ``` 43 | ### Center 44 | Constraining the center of a view to its superview with `NSLayoutConstraint`: 45 | 46 | ```swift 47 | NSLayoutConstraint.activate([ 48 | view.centerXAnchor.constraint(equalTo: superview.centerXAnchor, constant: 0) 49 | view.centerYAnchor.constraint(equalTo: superview.centerYAnchor, constant: 0) 50 | ]) 51 | ``` 52 | 53 | with `TinyConstraints`: 54 | 55 | ```swift 56 | view.center(in: superview) 57 | ``` 58 | 59 | or: 60 | 61 | ```swift 62 | view.center(in: superview, offset: CGPoint(x: 10, y: 10)) 63 | ``` 64 | 65 | ## Basic Use 66 | 67 | ### Typealiases 68 | 69 | `TinyConstraints` gives you convenient and tiny typealiases for handling constraints. 70 | 71 | - `Constraint` = `NSLayoutConstraint` 72 | - `Constraints` = `[NSLayoutConstraint]` 73 | 74 | ### Equal and Unequal Anchors 75 | This constraints the `top-anchor` of the view to the `top-anchor` of the superview: 76 | 77 | ```swift 78 | view.top(to: superview) 79 | ``` 80 | 81 | This constraints the `top-anchor` of `firstView` to the `bottom-anchor` of `secondView`: 82 | 83 | ```swift 84 | firstView.topToBottom(of: secondView) 85 | ``` 86 | 87 | ### Constrain to Superview 88 | Often you need to constrain a view to it's superview, with TinyConstraints you can do this super easy: 89 | 90 | ```swift 91 | view.edgesToSuperview() 92 | ``` 93 | 94 | Or only one edge: 95 | 96 | ```swift 97 | view.topToSuperview() 98 | ``` 99 | 100 | Or you can attach all edges except one, like this: 101 | 102 | ```swift 103 | view.edgesToSuperview(excluding: .bottom) 104 | ``` 105 | 106 | ### Relation and Priority 107 | For almost all constraints you can set the `relation` and `priority` properties. The default relation is `.equal` and the default priority is `.required`: 108 | 109 | ```swift 110 | container.width(150, relation: .equalOrLess, priority: .high) 111 | ``` 112 | 113 | ### Storing Constraints 114 | Here we create a set of inactive constraints and store these to our property: 115 | 116 | ```swift 117 | let constraints = view.size(CGSize(width: 100, height: 100), isActive: false) 118 | ``` 119 | 120 | ### Activation and Deactivation 121 | Besides the default `NSLayoutConstraint` activation, `TinyConstraints` also provides a way to activate *a set* of constraints: 122 | 123 | ```swift 124 | constraints.activate() 125 | ``` 126 | 127 | You can also do this in an animation: 128 | 129 | ```swift 130 | oldConstraints.deActivate() 131 | 132 | constraints.activate() 133 | UIViewPropertyAnimator(duration: 1, dampingRatio: 0.4) { 134 | self.layoutIfNeeded() 135 | }.startAnimation() 136 | ``` 137 | 138 | ### Animating Constraint Constants 139 | Here we add a height constraint to a view, store it and animate it later: 140 | 141 | ```swift 142 | let height = view.height(100) 143 | 144 | height.constant = 200 145 | UIViewPropertyAnimator(duration: 1, dampingRatio: 0.4) { 146 | self.layoutIfNeeded() 147 | }.startAnimation() 148 | ``` 149 | 150 | ### Stack 151 | Stack provides a way of constraining views together in a superview: 152 | 153 | ```swift 154 | let views = [logo, title, description] 155 | superview.stack(views, axis: .vertical, spacing: 10) 156 | ``` 157 | 158 | ##### Find these examples and more in the *Example Project*. 159 | 160 | ## Installation 161 | 162 | ### CocoaPods 163 | 164 | TinyConstraints is available through [CocoaPods](http://cocoapods.org). To install 165 | it, simply add the following line to your Podfile: 166 | 167 | ```ruby 168 | pod "TinyConstraints" 169 | ``` 170 | 171 | ### Carthage 172 | 173 | TinyConstraints is available through [Carthage](https://github.com/Carthage/Carthage). To install 174 | it, simply add the following line to your Cartfile: 175 | 176 | ``` 177 | github "roberthein/TinyConstraints" 178 | ``` 179 | 180 | ### Swift Package Manager 181 | 182 | TinyConstraints is available through [Swift Package Manager](https://swift.org/package-manager/). To install 183 | it, in Xcode 11.0 or later select `File` > `Swift Packages` > `Add Package Dependency...` and add TinyConstraints repository URL: 184 | ``` 185 | https://github.com/roberthein/TinyConstraints.git 186 | ``` 187 | 188 | ## Tutorials 189 | 190 | Here are some [video tutorials](https://www.youtube.com/playlist?list=PL_csAAO9PQ8ZDbGk57RlBRnNpxBGBAEOc) made by [Alex Nagy](https://github.com/rebeloper). 191 | 192 | 193 | ## Suggestions or feedback? 194 | 195 | Feel free to create a pull request, open an issue or find [me on Twitter](https://twitter.com/roberthein). 196 | -------------------------------------------------------------------------------- /TinyConstraints.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = 'TinyConstraints' 3 | s.version = '4.0.2' 4 | s.swift_versions = [5.0] 5 | s.summary = 'TinyConstraints is the syntactic sugar that makes Auto Layout sweeter for human use.' 6 | s.description = <<-DESC 7 | TinyConstraints is the syntactic sugar library that makes Auto Layout sweeter for human use. 8 | DESC 9 | s.homepage = 'https://github.com/roberthein/TinyConstraints' 10 | s.license = { :type => 'MIT', :file => 'LICENSE' } 11 | s.author = { 'Robert-Hein Hooijmans' => 'rh.hooijmans@gmail.com' } 12 | s.source = { :git => 'https://github.com/roberthein/TinyConstraints.git', :tag => s.version.to_s } 13 | s.social_media_url = 'https://twitter.com/roberthein' 14 | s.ios.deployment_target = '9.0' 15 | s.tvos.deployment_target = '9.0' 16 | s.osx.deployment_target = '10.11' 17 | s.source_files = 'TinyConstraints/Classes/**/*.{swift}' 18 | end 19 | -------------------------------------------------------------------------------- /TinyConstraints.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 2DD7AA441E599FD800509EBC /* Constrainable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2DD7AA431E599FD800509EBC /* Constrainable.swift */; }; 11 | 2DD987001E4DB973002F80D6 /* TinyConstraints.h in Headers */ = {isa = PBXBuildFile; fileRef = 2DD986FE1E4DB973002F80D6 /* TinyConstraints.h */; settings = {ATTRIBUTES = (Public, ); }; }; 12 | 2DD9870F1E4DBB6A002F80D6 /* Constraints.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2DD9870A1E4DBB6A002F80D6 /* Constraints.swift */; }; 13 | 2DD987101E4DBB6A002F80D6 /* Stack.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2DD9870B1E4DBB6A002F80D6 /* Stack.swift */; }; 14 | 2DD987111E4DBB6A002F80D6 /* TinyConstraints.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2DD9870C1E4DBB6A002F80D6 /* TinyConstraints.swift */; }; 15 | A932CB751F78081B00401861 /* TinyConstraints+superview.swift in Sources */ = {isa = PBXBuildFile; fileRef = A932CB741F78081B00401861 /* TinyConstraints+superview.swift */; }; 16 | A97552CE2128478300C1EC7E /* TinyEdgeInsets.swift in Sources */ = {isa = PBXBuildFile; fileRef = A97552CD2128478300C1EC7E /* TinyEdgeInsets.swift */; }; 17 | A9D467D11E6777CA00C331FA /* Abstraction.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9D467D01E6777CA00C331FA /* Abstraction.swift */; }; 18 | /* End PBXBuildFile section */ 19 | 20 | /* Begin PBXFileReference section */ 21 | 2DD7AA431E599FD800509EBC /* Constrainable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Constrainable.swift; sourceTree = ""; }; 22 | 2DD986FB1E4DB973002F80D6 /* TinyConstraints.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = TinyConstraints.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 23 | 2DD986FE1E4DB973002F80D6 /* TinyConstraints.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TinyConstraints.h; sourceTree = ""; }; 24 | 2DD986FF1E4DB973002F80D6 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 25 | 2DD9870A1E4DBB6A002F80D6 /* Constraints.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Constraints.swift; sourceTree = ""; }; 26 | 2DD9870B1E4DBB6A002F80D6 /* Stack.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Stack.swift; sourceTree = ""; }; 27 | 2DD9870C1E4DBB6A002F80D6 /* TinyConstraints.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TinyConstraints.swift; sourceTree = ""; }; 28 | 90CB57961FB3C77700379457 /* Universal-Framework-Target.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "Universal-Framework-Target.xcconfig"; sourceTree = ""; }; 29 | 90CB57981FB3C77700379457 /* Universal-Target-Base.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "Universal-Target-Base.xcconfig"; sourceTree = ""; }; 30 | A932CB741F78081B00401861 /* TinyConstraints+superview.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "TinyConstraints+superview.swift"; sourceTree = ""; }; 31 | A97552CD2128478300C1EC7E /* TinyEdgeInsets.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TinyEdgeInsets.swift; sourceTree = ""; }; 32 | A9D467D01E6777CA00C331FA /* Abstraction.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Abstraction.swift; sourceTree = ""; }; 33 | /* End PBXFileReference section */ 34 | 35 | /* Begin PBXFrameworksBuildPhase section */ 36 | 2DD986F71E4DB973002F80D6 /* Frameworks */ = { 37 | isa = PBXFrameworksBuildPhase; 38 | buildActionMask = 2147483647; 39 | files = ( 40 | ); 41 | runOnlyForDeploymentPostprocessing = 0; 42 | }; 43 | /* End PBXFrameworksBuildPhase section */ 44 | 45 | /* Begin PBXGroup section */ 46 | 2DD986F11E4DB973002F80D6 = { 47 | isa = PBXGroup; 48 | children = ( 49 | 2DD986FD1E4DB973002F80D6 /* TinyConstraints */, 50 | 2DD986FC1E4DB973002F80D6 /* Products */, 51 | ); 52 | sourceTree = ""; 53 | }; 54 | 2DD986FC1E4DB973002F80D6 /* Products */ = { 55 | isa = PBXGroup; 56 | children = ( 57 | 2DD986FB1E4DB973002F80D6 /* TinyConstraints.framework */, 58 | ); 59 | name = Products; 60 | sourceTree = ""; 61 | }; 62 | 2DD986FD1E4DB973002F80D6 /* TinyConstraints */ = { 63 | isa = PBXGroup; 64 | children = ( 65 | 90CB57951FB3C77700379457 /* Configurations */, 66 | 2DD987081E4DBB6A002F80D6 /* Classes */, 67 | 2DD986FE1E4DB973002F80D6 /* TinyConstraints.h */, 68 | 2DD986FF1E4DB973002F80D6 /* Info.plist */, 69 | ); 70 | path = TinyConstraints; 71 | sourceTree = ""; 72 | }; 73 | 2DD987081E4DBB6A002F80D6 /* Classes */ = { 74 | isa = PBXGroup; 75 | children = ( 76 | A9D467D01E6777CA00C331FA /* Abstraction.swift */, 77 | 2DD7AA431E599FD800509EBC /* Constrainable.swift */, 78 | 2DD9870A1E4DBB6A002F80D6 /* Constraints.swift */, 79 | 2DD9870B1E4DBB6A002F80D6 /* Stack.swift */, 80 | 2DD9870C1E4DBB6A002F80D6 /* TinyConstraints.swift */, 81 | A932CB741F78081B00401861 /* TinyConstraints+superview.swift */, 82 | A97552CD2128478300C1EC7E /* TinyEdgeInsets.swift */, 83 | ); 84 | path = Classes; 85 | sourceTree = ""; 86 | }; 87 | 90CB57951FB3C77700379457 /* Configurations */ = { 88 | isa = PBXGroup; 89 | children = ( 90 | 90CB57961FB3C77700379457 /* Universal-Framework-Target.xcconfig */, 91 | 90CB57981FB3C77700379457 /* Universal-Target-Base.xcconfig */, 92 | ); 93 | path = Configurations; 94 | sourceTree = SOURCE_ROOT; 95 | }; 96 | /* End PBXGroup section */ 97 | 98 | /* Begin PBXHeadersBuildPhase section */ 99 | 2DD986F81E4DB973002F80D6 /* Headers */ = { 100 | isa = PBXHeadersBuildPhase; 101 | buildActionMask = 2147483647; 102 | files = ( 103 | 2DD987001E4DB973002F80D6 /* TinyConstraints.h in Headers */, 104 | ); 105 | runOnlyForDeploymentPostprocessing = 0; 106 | }; 107 | /* End PBXHeadersBuildPhase section */ 108 | 109 | /* Begin PBXNativeTarget section */ 110 | 2DD986FA1E4DB973002F80D6 /* TinyConstraints */ = { 111 | isa = PBXNativeTarget; 112 | buildConfigurationList = 2DD987031E4DB973002F80D6 /* Build configuration list for PBXNativeTarget "TinyConstraints" */; 113 | buildPhases = ( 114 | 2DD986F61E4DB973002F80D6 /* Sources */, 115 | 2DD986F71E4DB973002F80D6 /* Frameworks */, 116 | 2DD986F81E4DB973002F80D6 /* Headers */, 117 | 2DD986F91E4DB973002F80D6 /* Resources */, 118 | ); 119 | buildRules = ( 120 | ); 121 | dependencies = ( 122 | ); 123 | name = TinyConstraints; 124 | productName = TinyConstraints; 125 | productReference = 2DD986FB1E4DB973002F80D6 /* TinyConstraints.framework */; 126 | productType = "com.apple.product-type.framework"; 127 | }; 128 | /* End PBXNativeTarget section */ 129 | 130 | /* Begin PBXProject section */ 131 | 2DD986F21E4DB973002F80D6 /* Project object */ = { 132 | isa = PBXProject; 133 | attributes = { 134 | LastUpgradeCheck = 1020; 135 | ORGANIZATIONNAME = "Robert-Hein Hooijmans"; 136 | TargetAttributes = { 137 | 2DD986FA1E4DB973002F80D6 = { 138 | CreatedOnToolsVersion = 8.2.1; 139 | LastSwiftMigration = 1020; 140 | ProvisioningStyle = Manual; 141 | }; 142 | }; 143 | }; 144 | buildConfigurationList = 2DD986F51E4DB973002F80D6 /* Build configuration list for PBXProject "TinyConstraints" */; 145 | compatibilityVersion = "Xcode 3.2"; 146 | developmentRegion = en; 147 | hasScannedForEncodings = 0; 148 | knownRegions = ( 149 | en, 150 | Base, 151 | ); 152 | mainGroup = 2DD986F11E4DB973002F80D6; 153 | productRefGroup = 2DD986FC1E4DB973002F80D6 /* Products */; 154 | projectDirPath = ""; 155 | projectRoot = ""; 156 | targets = ( 157 | 2DD986FA1E4DB973002F80D6 /* TinyConstraints */, 158 | ); 159 | }; 160 | /* End PBXProject section */ 161 | 162 | /* Begin PBXResourcesBuildPhase section */ 163 | 2DD986F91E4DB973002F80D6 /* Resources */ = { 164 | isa = PBXResourcesBuildPhase; 165 | buildActionMask = 2147483647; 166 | files = ( 167 | ); 168 | runOnlyForDeploymentPostprocessing = 0; 169 | }; 170 | /* End PBXResourcesBuildPhase section */ 171 | 172 | /* Begin PBXSourcesBuildPhase section */ 173 | 2DD986F61E4DB973002F80D6 /* Sources */ = { 174 | isa = PBXSourcesBuildPhase; 175 | buildActionMask = 2147483647; 176 | files = ( 177 | A97552CE2128478300C1EC7E /* TinyEdgeInsets.swift in Sources */, 178 | 2DD987111E4DBB6A002F80D6 /* TinyConstraints.swift in Sources */, 179 | A932CB751F78081B00401861 /* TinyConstraints+superview.swift in Sources */, 180 | 2DD987101E4DBB6A002F80D6 /* Stack.swift in Sources */, 181 | 2DD9870F1E4DBB6A002F80D6 /* Constraints.swift in Sources */, 182 | 2DD7AA441E599FD800509EBC /* Constrainable.swift in Sources */, 183 | A9D467D11E6777CA00C331FA /* Abstraction.swift in Sources */, 184 | ); 185 | runOnlyForDeploymentPostprocessing = 0; 186 | }; 187 | /* End PBXSourcesBuildPhase section */ 188 | 189 | /* Begin XCBuildConfiguration section */ 190 | 2DD987011E4DB973002F80D6 /* Debug */ = { 191 | isa = XCBuildConfiguration; 192 | buildSettings = { 193 | ALWAYS_SEARCH_USER_PATHS = NO; 194 | CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; 195 | CLANG_ANALYZER_NONNULL = YES; 196 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 197 | CLANG_CXX_LIBRARY = "libc++"; 198 | CLANG_ENABLE_CODE_COVERAGE = NO; 199 | CLANG_ENABLE_MODULES = YES; 200 | CLANG_ENABLE_OBJC_ARC = YES; 201 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 202 | CLANG_WARN_BOOL_CONVERSION = YES; 203 | CLANG_WARN_COMMA = YES; 204 | CLANG_WARN_CONSTANT_CONVERSION = YES; 205 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 206 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 207 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 208 | CLANG_WARN_EMPTY_BODY = YES; 209 | CLANG_WARN_ENUM_CONVERSION = YES; 210 | CLANG_WARN_INFINITE_RECURSION = YES; 211 | CLANG_WARN_INT_CONVERSION = YES; 212 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 213 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 214 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 215 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 216 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 217 | CLANG_WARN_STRICT_PROTOTYPES = YES; 218 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 219 | CLANG_WARN_UNREACHABLE_CODE = YES; 220 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 221 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 222 | COPY_PHASE_STRIP = NO; 223 | CURRENT_PROJECT_VERSION = 1; 224 | DEBUG_INFORMATION_FORMAT = dwarf; 225 | ENABLE_STRICT_OBJC_MSGSEND = YES; 226 | ENABLE_TESTABILITY = YES; 227 | GCC_C_LANGUAGE_STANDARD = gnu99; 228 | GCC_DYNAMIC_NO_PIC = NO; 229 | GCC_NO_COMMON_BLOCKS = YES; 230 | GCC_OPTIMIZATION_LEVEL = 0; 231 | GCC_PREPROCESSOR_DEFINITIONS = ( 232 | "DEBUG=1", 233 | "$(inherited)", 234 | ); 235 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 236 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 237 | GCC_WARN_UNDECLARED_SELECTOR = YES; 238 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 239 | GCC_WARN_UNUSED_FUNCTION = YES; 240 | GCC_WARN_UNUSED_VARIABLE = YES; 241 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 242 | MACOSX_DEPLOYMENT_TARGET = 10.11; 243 | MTL_ENABLE_DEBUG_INFO = YES; 244 | ONLY_ACTIVE_ARCH = YES; 245 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 246 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 247 | SWIFT_VERSION = 5.0; 248 | TARGETED_DEVICE_FAMILY = "1,2"; 249 | TVOS_DEPLOYMENT_TARGET = 10.0; 250 | VERSIONING_SYSTEM = "apple-generic"; 251 | VERSION_INFO_PREFIX = ""; 252 | }; 253 | name = Debug; 254 | }; 255 | 2DD987021E4DB973002F80D6 /* Release */ = { 256 | isa = XCBuildConfiguration; 257 | buildSettings = { 258 | ALWAYS_SEARCH_USER_PATHS = NO; 259 | CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; 260 | CLANG_ANALYZER_NONNULL = YES; 261 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 262 | CLANG_CXX_LIBRARY = "libc++"; 263 | CLANG_ENABLE_CODE_COVERAGE = NO; 264 | CLANG_ENABLE_MODULES = YES; 265 | CLANG_ENABLE_OBJC_ARC = YES; 266 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 267 | CLANG_WARN_BOOL_CONVERSION = YES; 268 | CLANG_WARN_COMMA = YES; 269 | CLANG_WARN_CONSTANT_CONVERSION = YES; 270 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 271 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 272 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 273 | CLANG_WARN_EMPTY_BODY = YES; 274 | CLANG_WARN_ENUM_CONVERSION = YES; 275 | CLANG_WARN_INFINITE_RECURSION = YES; 276 | CLANG_WARN_INT_CONVERSION = YES; 277 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 278 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 279 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 280 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 281 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 282 | CLANG_WARN_STRICT_PROTOTYPES = YES; 283 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 284 | CLANG_WARN_UNREACHABLE_CODE = YES; 285 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 286 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 287 | COPY_PHASE_STRIP = NO; 288 | CURRENT_PROJECT_VERSION = 1; 289 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 290 | ENABLE_NS_ASSERTIONS = NO; 291 | ENABLE_STRICT_OBJC_MSGSEND = YES; 292 | GCC_C_LANGUAGE_STANDARD = gnu99; 293 | GCC_NO_COMMON_BLOCKS = YES; 294 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 295 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 296 | GCC_WARN_UNDECLARED_SELECTOR = YES; 297 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 298 | GCC_WARN_UNUSED_FUNCTION = YES; 299 | GCC_WARN_UNUSED_VARIABLE = YES; 300 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 301 | MACOSX_DEPLOYMENT_TARGET = 10.11; 302 | MTL_ENABLE_DEBUG_INFO = NO; 303 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 304 | SWIFT_VERSION = 5.0; 305 | TARGETED_DEVICE_FAMILY = "1,2"; 306 | TVOS_DEPLOYMENT_TARGET = 10.0; 307 | VALIDATE_PRODUCT = YES; 308 | VERSIONING_SYSTEM = "apple-generic"; 309 | VERSION_INFO_PREFIX = ""; 310 | }; 311 | name = Release; 312 | }; 313 | 2DD987041E4DB973002F80D6 /* Debug */ = { 314 | isa = XCBuildConfiguration; 315 | baseConfigurationReference = 90CB57961FB3C77700379457 /* Universal-Framework-Target.xcconfig */; 316 | buildSettings = { 317 | APPLICATION_EXTENSION_API_ONLY = YES; 318 | CLANG_ENABLE_CODE_COVERAGE = NO; 319 | CODE_SIGN_IDENTITY = ""; 320 | DEFINES_MODULE = YES; 321 | DEVELOPMENT_TEAM = ""; 322 | DYLIB_COMPATIBILITY_VERSION = 1; 323 | DYLIB_CURRENT_VERSION = 1; 324 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 325 | INFOPLIST_FILE = TinyConstraints/Info.plist; 326 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 327 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 328 | PRODUCT_BUNDLE_IDENTIFIER = com.roberthein.TinyConstraints; 329 | PRODUCT_NAME = "$(TARGET_NAME)"; 330 | SKIP_INSTALL = YES; 331 | SWIFT_VERSION = 5.0; 332 | }; 333 | name = Debug; 334 | }; 335 | 2DD987051E4DB973002F80D6 /* Release */ = { 336 | isa = XCBuildConfiguration; 337 | baseConfigurationReference = 90CB57961FB3C77700379457 /* Universal-Framework-Target.xcconfig */; 338 | buildSettings = { 339 | APPLICATION_EXTENSION_API_ONLY = YES; 340 | CLANG_ENABLE_CODE_COVERAGE = NO; 341 | CODE_SIGN_IDENTITY = ""; 342 | DEFINES_MODULE = YES; 343 | DEVELOPMENT_TEAM = ""; 344 | DYLIB_COMPATIBILITY_VERSION = 1; 345 | DYLIB_CURRENT_VERSION = 1; 346 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 347 | INFOPLIST_FILE = TinyConstraints/Info.plist; 348 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 349 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 350 | PRODUCT_BUNDLE_IDENTIFIER = com.roberthein.TinyConstraints; 351 | PRODUCT_NAME = "$(TARGET_NAME)"; 352 | SKIP_INSTALL = YES; 353 | SWIFT_VERSION = 5.0; 354 | }; 355 | name = Release; 356 | }; 357 | /* End XCBuildConfiguration section */ 358 | 359 | /* Begin XCConfigurationList section */ 360 | 2DD986F51E4DB973002F80D6 /* Build configuration list for PBXProject "TinyConstraints" */ = { 361 | isa = XCConfigurationList; 362 | buildConfigurations = ( 363 | 2DD987011E4DB973002F80D6 /* Debug */, 364 | 2DD987021E4DB973002F80D6 /* Release */, 365 | ); 366 | defaultConfigurationIsVisible = 0; 367 | defaultConfigurationName = Release; 368 | }; 369 | 2DD987031E4DB973002F80D6 /* Build configuration list for PBXNativeTarget "TinyConstraints" */ = { 370 | isa = XCConfigurationList; 371 | buildConfigurations = ( 372 | 2DD987041E4DB973002F80D6 /* Debug */, 373 | 2DD987051E4DB973002F80D6 /* Release */, 374 | ); 375 | defaultConfigurationIsVisible = 0; 376 | defaultConfigurationName = Release; 377 | }; 378 | /* End XCConfigurationList section */ 379 | }; 380 | rootObject = 2DD986F21E4DB973002F80D6 /* Project object */; 381 | } 382 | -------------------------------------------------------------------------------- /TinyConstraints.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /TinyConstraints.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /TinyConstraints.xcodeproj/xcshareddata/xcschemes/TinyConstraints.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 34 | 35 | 45 | 46 | 52 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 70 | 71 | 72 | 73 | 75 | 76 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /TinyConstraints/Classes/Abstraction.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MIT License 3 | // 4 | // Copyright (c) 2017 Robert-Hein Hooijmans 5 | // 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy 7 | // of this software and associated documentation files (the "Software"), to deal 8 | // in the Software without restriction, including without limitation the rights 9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the Software is 11 | // furnished to do so, subject to the following conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be included in 14 | // all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | // THE SOFTWARE. 23 | 24 | import Foundation 25 | 26 | #if os(OSX) 27 | import AppKit 28 | 29 | public typealias TinyView = NSView 30 | public typealias LayoutGuide = NSLayoutGuide 31 | public typealias ConstraintAxis = NSLayoutConstraint.Orientation 32 | public typealias LayoutPriority = NSLayoutConstraint.Priority 33 | public typealias TinyEdgeInsets = NSEdgeInsets 34 | 35 | public extension NSEdgeInsets { 36 | static var zero = NSEdgeInsetsZero 37 | } 38 | #else 39 | import UIKit 40 | 41 | public typealias TinyView = UIView 42 | public typealias LayoutGuide = UILayoutGuide 43 | public typealias ConstraintAxis = NSLayoutConstraint.Axis 44 | public typealias LayoutPriority = UILayoutPriority 45 | 46 | public typealias TinyEdgeInsets = UIEdgeInsets 47 | #endif 48 | 49 | -------------------------------------------------------------------------------- /TinyConstraints/Classes/Constrainable.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MIT License 3 | // 4 | // Copyright (c) 2017 Robert-Hein Hooijmans 5 | // 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy 7 | // of this software and associated documentation files (the "Software"), to deal 8 | // in the Software without restriction, including without limitation the rights 9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the Software is 11 | // furnished to do so, subject to the following conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be included in 14 | // all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | // THE SOFTWARE. 23 | 24 | #if os(OSX) 25 | import AppKit 26 | #else 27 | import UIKit 28 | #endif 29 | 30 | extension TinyView: Constrainable { 31 | 32 | @discardableResult 33 | public func prepareForLayout() -> Self { 34 | translatesAutoresizingMaskIntoConstraints = false 35 | return self 36 | } 37 | } 38 | 39 | extension LayoutGuide: Constrainable { 40 | @discardableResult 41 | public func prepareForLayout() -> Self { return self } 42 | } 43 | 44 | public protocol Constrainable { 45 | var topAnchor: NSLayoutYAxisAnchor { get } 46 | var bottomAnchor: NSLayoutYAxisAnchor { get } 47 | var leftAnchor: NSLayoutXAxisAnchor { get } 48 | var rightAnchor: NSLayoutXAxisAnchor { get } 49 | var leadingAnchor: NSLayoutXAxisAnchor { get } 50 | var trailingAnchor: NSLayoutXAxisAnchor { get } 51 | 52 | var centerXAnchor: NSLayoutXAxisAnchor { get } 53 | var centerYAnchor: NSLayoutYAxisAnchor { get } 54 | 55 | var widthAnchor: NSLayoutDimension { get } 56 | var heightAnchor: NSLayoutDimension { get } 57 | 58 | @discardableResult 59 | func prepareForLayout() -> Self 60 | } 61 | -------------------------------------------------------------------------------- /TinyConstraints/Classes/Constraints.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MIT License 3 | // 4 | // Copyright (c) 2017 Robert-Hein Hooijmans 5 | // 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy 7 | // of this software and associated documentation files (the "Software"), to deal 8 | // in the Software without restriction, including without limitation the rights 9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the Software is 11 | // furnished to do so, subject to the following conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be included in 14 | // all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | // THE SOFTWARE. 23 | // 24 | 25 | #if os(OSX) 26 | import AppKit 27 | #else 28 | import UIKit 29 | #endif 30 | 31 | public typealias Constraint = NSLayoutConstraint 32 | public typealias Constraints = [Constraint] 33 | 34 | public enum ConstraintRelation: Int { 35 | case equal = 0 36 | case equalOrLess = -1 37 | case equalOrGreater = 1 38 | } 39 | 40 | public extension Collection where Iterator.Element == Constraint { 41 | 42 | func activate() { 43 | 44 | if let constraints = self as? Constraints { 45 | Constraint.activate(constraints) 46 | } 47 | } 48 | 49 | func deActivate() { 50 | 51 | if let constraints = self as? Constraints { 52 | Constraint.deactivate(constraints) 53 | } 54 | } 55 | } 56 | 57 | #if os(OSX) 58 | public extension Constraint { 59 | @objc 60 | func with(_ p: Constraint.Priority) -> Self { 61 | priority = p 62 | return self 63 | } 64 | 65 | func set(_ active: Bool) -> Self { 66 | isActive = active 67 | return self 68 | } 69 | } 70 | #else 71 | public extension Constraint { 72 | @objc 73 | func with(_ p: LayoutPriority) -> Self { 74 | priority = p 75 | return self 76 | } 77 | 78 | func set(_ active: Bool) -> Self { 79 | isActive = active 80 | return self 81 | } 82 | } 83 | #endif 84 | 85 | -------------------------------------------------------------------------------- /TinyConstraints/Classes/Stack.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MIT License 3 | // 4 | // Copyright (c) 2017 Robert-Hein Hooijmans 5 | // 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy 7 | // of this software and associated documentation files (the "Software"), to deal 8 | // in the Software without restriction, including without limitation the rights 9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the Software is 11 | // furnished to do so, subject to the following conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be included in 14 | // all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | // THE SOFTWARE. 23 | // 24 | 25 | #if os(OSX) 26 | import AppKit 27 | #else 28 | import UIKit 29 | #endif 30 | 31 | public extension TinyView { 32 | 33 | @discardableResult 34 | func stack(_ views: [TinyView], axis: ConstraintAxis = .vertical, width: CGFloat? = nil, height: CGFloat? = nil, spacing: CGFloat = 0) -> Constraints { 35 | 36 | translatesAutoresizingMaskIntoConstraints = false 37 | 38 | var offset: CGFloat = 0 39 | var previous: TinyView? 40 | var constraints: Constraints = [] 41 | 42 | for view in views { 43 | view.translatesAutoresizingMaskIntoConstraints = false 44 | addSubview(view) 45 | 46 | switch axis { 47 | case .vertical: 48 | constraints.append(view.top(to: previous ?? self, previous?.bottomAnchor ?? topAnchor, offset: offset)) 49 | constraints.append(view.leftToSuperview()) 50 | constraints.append(view.rightToSuperview()) 51 | 52 | if let lastView = views.last, view == lastView { 53 | constraints.append(view.bottomToSuperview()) 54 | } 55 | case .horizontal: 56 | constraints.append(view.topToSuperview()) 57 | constraints.append(view.bottomToSuperview()) 58 | constraints.append(view.left(to: previous ?? self, previous?.rightAnchor ?? leftAnchor, offset: offset)) 59 | 60 | if let lastView = views.last, view == lastView { 61 | constraints.append(view.rightToSuperview()) 62 | } 63 | @unknown default: 64 | fatalError() 65 | } 66 | 67 | if let width = width { 68 | constraints.append(view.width(width)) 69 | } 70 | 71 | if let height = height { 72 | constraints.append(view.height(height)) 73 | } 74 | 75 | offset = spacing 76 | previous = view 77 | } 78 | 79 | return constraints 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /TinyConstraints/Classes/TinyConstraints+superview.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MIT License 3 | // 4 | // Copyright (c) 2017 Robert-Hein Hooijmans 5 | // 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy 7 | // of this software and associated documentation files (the "Software"), to deal 8 | // in the Software without restriction, including without limitation the rights 9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the Software is 11 | // furnished to do so, subject to the following conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be included in 14 | // all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | // THE SOFTWARE. 23 | // 24 | 25 | #if os(OSX) 26 | import AppKit 27 | 28 | public extension TinyView { 29 | 30 | @discardableResult 31 | func edgesToSuperview(excluding excludedEdge: LayoutEdge = .none, insets: TinyEdgeInsets = .zero, usingSafeArea: Bool = false) -> Constraints { 32 | var constraints = Constraints() 33 | 34 | if !excludedEdge.contains(.top) { 35 | constraints.append(topToSuperview(offset: insets.top, usingSafeArea: usingSafeArea)) 36 | } 37 | 38 | if !excludedEdge.contains(.left) { 39 | constraints.append(leftToSuperview(offset: insets.left, usingSafeArea: usingSafeArea)) 40 | } 41 | 42 | if !excludedEdge.contains(.right) { 43 | constraints.append(rightToSuperview(offset: -insets.right, usingSafeArea: usingSafeArea)) 44 | } 45 | 46 | if !excludedEdge.contains(.bottom) { 47 | constraints.append(bottomToSuperview(offset: -insets.bottom, usingSafeArea: usingSafeArea)) 48 | } 49 | 50 | return constraints 51 | } 52 | } 53 | #else 54 | import UIKit 55 | 56 | public extension TinyView { 57 | 58 | @available(tvOS 10.0, *) 59 | @available(iOS 10.0, *) 60 | @discardableResult 61 | func edgesToSuperview(excluding excludedEdge: LayoutEdge = .none, insets: TinyEdgeInsets = .zero, relation: ConstraintRelation = .equal, priority: LayoutPriority = .required, isActive: Bool = true, usingSafeArea: Bool = false) -> Constraints { 62 | var constraints = Constraints() 63 | 64 | if !excludedEdge.contains(.top) { 65 | constraints.append(topToSuperview(offset: insets.top, relation: relation, priority: priority, isActive: isActive, usingSafeArea: usingSafeArea)) 66 | } 67 | 68 | if effectiveUserInterfaceLayoutDirection == .leftToRight { 69 | 70 | if !(excludedEdge.contains(.leading) || excludedEdge.contains(.left)) { 71 | constraints.append(leftToSuperview(offset: insets.left, relation: relation, priority: priority, isActive: isActive, usingSafeArea: usingSafeArea)) 72 | } 73 | 74 | if !(excludedEdge.contains(.trailing) || excludedEdge.contains(.right)) { 75 | constraints.append(rightToSuperview(offset: -insets.right, relation: relation, priority: priority, isActive: isActive, usingSafeArea: usingSafeArea)) 76 | } 77 | } else { 78 | 79 | if !(excludedEdge.contains(.leading) || excludedEdge.contains(.right)) { 80 | constraints.append(rightToSuperview(offset: -insets.right, relation: relation, priority: priority, isActive: isActive, usingSafeArea: usingSafeArea)) 81 | } 82 | 83 | if !(excludedEdge.contains(.trailing) || excludedEdge.contains(.left)) { 84 | constraints.append(leftToSuperview(offset: insets.left, relation: relation, priority: priority, isActive: isActive, usingSafeArea: usingSafeArea)) 85 | } 86 | } 87 | 88 | if !excludedEdge.contains(.bottom) { 89 | constraints.append(bottomToSuperview(offset: -insets.bottom, relation: relation, priority: priority, isActive: isActive, usingSafeArea: usingSafeArea)) 90 | } 91 | 92 | return constraints 93 | } 94 | 95 | @available(tvOS 10.0, *) 96 | @available(iOS 10.0, *) 97 | @discardableResult 98 | func leadingToSuperview( _ anchor: NSLayoutXAxisAnchor? = nil, offset: CGFloat = 0, relation: ConstraintRelation = .equal, priority: LayoutPriority = .required, isActive: Bool = true, usingSafeArea: Bool = false) -> Constraint { 99 | let constrainable = safeConstrainable(for: superview, usingSafeArea: usingSafeArea) 100 | 101 | if effectiveUserInterfaceLayoutDirection == .rightToLeft { 102 | return leading(to: constrainable, anchor, offset: -offset, relation: relation, priority: priority, isActive: isActive) 103 | } else { 104 | return leading(to: constrainable, anchor, offset: offset, relation: relation, priority: priority, isActive: isActive) 105 | } 106 | } 107 | 108 | @available(tvOS 10.0, *) 109 | @available(iOS 10.0, *) 110 | @discardableResult 111 | func trailingToSuperview( _ anchor: NSLayoutXAxisAnchor? = nil, offset: CGFloat = 0, relation: ConstraintRelation = .equal, priority: LayoutPriority = .required, isActive: Bool = true, usingSafeArea: Bool = false) -> Constraint { 112 | let constrainable = safeConstrainable(for: superview, usingSafeArea: usingSafeArea) 113 | 114 | if effectiveUserInterfaceLayoutDirection == .rightToLeft { 115 | return trailing(to: constrainable, anchor, offset: offset, relation: relation, priority: priority, isActive: isActive) 116 | } else { 117 | return trailing(to: constrainable, anchor, offset: -offset, relation: relation, priority: priority, isActive: isActive) 118 | } 119 | } 120 | 121 | @available(tvOS 10.0, *) 122 | @available(iOS 10.0, *) 123 | @discardableResult 124 | func horizontalToSuperview(insets: TinyEdgeInsets = .zero, relation: ConstraintRelation = .equal, priority: LayoutPriority = .required, isActive: Bool = true, usingSafeArea: Bool = false) -> Constraints { 125 | 126 | var constraints = Constraints() 127 | 128 | if effectiveUserInterfaceLayoutDirection == .leftToRight { 129 | constraints.append(leftToSuperview(offset: insets.left, relation: relation, priority: priority, isActive: isActive, usingSafeArea: usingSafeArea)) 130 | constraints.append(rightToSuperview(offset: -insets.right, relation: relation, priority: priority, isActive: isActive, usingSafeArea: usingSafeArea)) 131 | } else { 132 | constraints.append(rightToSuperview(offset: -insets.right, relation: relation, priority: priority, isActive: isActive, usingSafeArea: usingSafeArea)) 133 | constraints.append(leftToSuperview(offset: insets.left, relation: relation, priority: priority, isActive: isActive, usingSafeArea: usingSafeArea)) 134 | } 135 | 136 | return constraints 137 | } 138 | 139 | @available(tvOS 10.0, *) 140 | @available(iOS 10.0, *) 141 | @discardableResult 142 | func verticalToSuperview(insets: TinyEdgeInsets = .zero, relation: ConstraintRelation = .equal, priority: LayoutPriority = .required, isActive: Bool = true, usingSafeArea: Bool = false) -> Constraints { 143 | 144 | let constraints = Constraints(arrayLiteral: 145 | topToSuperview(offset: insets.top, relation: relation, priority: priority, isActive: isActive, usingSafeArea: usingSafeArea), 146 | bottomToSuperview(offset: -insets.bottom, relation: relation, priority: priority, isActive: isActive, usingSafeArea: usingSafeArea) 147 | ) 148 | return constraints 149 | } 150 | } 151 | #endif 152 | 153 | public struct LayoutEdge: OptionSet { 154 | public let rawValue: UInt8 155 | public init(rawValue: UInt8) { 156 | self.rawValue = rawValue 157 | } 158 | public static let top = LayoutEdge(rawValue: 1 << 0) 159 | public static let bottom = LayoutEdge(rawValue: 1 << 1) 160 | public static let trailing = LayoutEdge(rawValue: 1 << 2) 161 | public static let leading = LayoutEdge(rawValue: 1 << 3) 162 | public static let left = LayoutEdge(rawValue: 1 << 4) 163 | public static let right = LayoutEdge(rawValue: 1 << 5) 164 | public static let none = LayoutEdge(rawValue: 1 << 6) 165 | } 166 | 167 | public extension TinyView { 168 | 169 | private func safeConstrainable(for superview: TinyView?, usingSafeArea: Bool) -> Constrainable { 170 | guard let superview = superview else { 171 | fatalError("Unable to create this constraint to it's superview, because it has no superview.") 172 | } 173 | 174 | prepareForLayout() 175 | 176 | #if os(iOS) || os(tvOS) 177 | if #available(iOS 11, tvOS 11, *){ 178 | if usingSafeArea { 179 | return superview.safeAreaLayoutGuide 180 | } 181 | } 182 | #endif 183 | 184 | return superview 185 | } 186 | 187 | 188 | @discardableResult 189 | func centerInSuperview(offset: CGPoint = .zero, priority: LayoutPriority = .required, isActive: Bool = true, usingSafeArea: Bool = false) -> Constraints { 190 | let constrainable = safeConstrainable(for: superview, usingSafeArea: usingSafeArea) 191 | return center(in: constrainable, offset: offset, priority: priority, isActive: isActive) 192 | } 193 | 194 | @discardableResult 195 | func originToSuperview(insets: TinyEdgeInsets = .zero, relation: ConstraintRelation = .equal, priority: LayoutPriority = .required, isActive: Bool = true, usingSafeArea: Bool = false) -> Constraints { 196 | let constrainable = safeConstrainable(for: superview, usingSafeArea: usingSafeArea) 197 | return origin(to: constrainable, insets: insets, relation: relation, priority: priority, isActive: isActive) 198 | } 199 | 200 | @discardableResult 201 | func widthToSuperview( _ dimension: NSLayoutDimension? = nil, multiplier: CGFloat = 1, offset: CGFloat = 0, relation: ConstraintRelation = .equal, priority: LayoutPriority = .required, isActive: Bool = true, usingSafeArea: Bool = false) -> Constraint { 202 | let constrainable = safeConstrainable(for: superview, usingSafeArea: usingSafeArea) 203 | return width(to: constrainable, dimension, multiplier: multiplier, offset: offset, relation: relation, priority: priority, isActive: isActive) 204 | } 205 | 206 | @discardableResult 207 | func heightToSuperview( _ dimension: NSLayoutDimension? = nil, multiplier: CGFloat = 1, offset: CGFloat = 0, relation: ConstraintRelation = .equal, priority: LayoutPriority = .required, isActive: Bool = true, usingSafeArea: Bool = false) -> Constraint { 208 | let constrainable = safeConstrainable(for: superview, usingSafeArea: usingSafeArea) 209 | return height(to: constrainable, dimension, multiplier: multiplier, offset: offset, relation: relation, priority: priority, isActive: isActive) 210 | } 211 | 212 | @discardableResult 213 | func leftToSuperview( _ anchor: NSLayoutXAxisAnchor? = nil, offset: CGFloat = 0, relation: ConstraintRelation = .equal, priority: LayoutPriority = .required, isActive: Bool = true, usingSafeArea: Bool = false) -> Constraint { 214 | let constrainable = safeConstrainable(for: superview, usingSafeArea: usingSafeArea) 215 | return left(to: constrainable, anchor, offset: offset, relation: relation, priority: priority, isActive: isActive) 216 | } 217 | 218 | @discardableResult 219 | func rightToSuperview( _ anchor: NSLayoutXAxisAnchor? = nil, offset: CGFloat = 0, relation: ConstraintRelation = .equal, priority: LayoutPriority = .required, isActive: Bool = true, usingSafeArea: Bool = false) -> Constraint { 220 | let constrainable = safeConstrainable(for: superview, usingSafeArea: usingSafeArea) 221 | return right(to: constrainable, anchor, offset: offset, relation: relation, priority: priority, isActive: isActive) 222 | } 223 | 224 | @discardableResult 225 | func topToSuperview( _ anchor: NSLayoutYAxisAnchor? = nil, offset: CGFloat = 0, relation: ConstraintRelation = .equal, priority: LayoutPriority = .required, isActive: Bool = true, usingSafeArea: Bool = false) -> Constraint { 226 | let constrainable = safeConstrainable(for: superview, usingSafeArea: usingSafeArea) 227 | return top(to: constrainable, anchor, offset: offset, relation: relation, priority: priority, isActive: isActive) 228 | } 229 | 230 | @discardableResult 231 | func bottomToSuperview( _ anchor: NSLayoutYAxisAnchor? = nil, offset: CGFloat = 0, relation: ConstraintRelation = .equal, priority: LayoutPriority = .required, isActive: Bool = true, usingSafeArea: Bool = false) -> Constraint { 232 | let constrainable = safeConstrainable(for: superview, usingSafeArea: usingSafeArea) 233 | return bottom(to: constrainable, anchor, offset: offset, relation: relation, priority: priority, isActive: isActive) 234 | } 235 | 236 | @discardableResult 237 | func centerXToSuperview( _ anchor: NSLayoutXAxisAnchor? = nil, multiplier: CGFloat = 1, offset: CGFloat = 0, priority: LayoutPriority = .required, isActive: Bool = true, usingSafeArea: Bool = false) -> Constraint { 238 | let constrainable = safeConstrainable(for: superview, usingSafeArea: usingSafeArea) 239 | return centerX(to: constrainable, anchor, multiplier: multiplier, offset: offset, priority: priority, isActive: isActive) 240 | } 241 | 242 | @discardableResult 243 | func centerYToSuperview( _ anchor: NSLayoutYAxisAnchor? = nil, multiplier: CGFloat = 1, offset: CGFloat = 0, priority: LayoutPriority = .required, isActive: Bool = true, usingSafeArea: Bool = false) -> Constraint { 244 | let constrainable = safeConstrainable(for: superview, usingSafeArea: usingSafeArea) 245 | return centerY(to: constrainable, anchor, multiplier: multiplier, offset: offset, priority: priority, isActive: isActive) 246 | } 247 | } 248 | -------------------------------------------------------------------------------- /TinyConstraints/Classes/TinyConstraints.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MIT License 3 | // 4 | // Copyright (c) 2017 Robert-Hein Hooijmans 5 | // 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy 7 | // of this software and associated documentation files (the "Software"), to deal 8 | // in the Software without restriction, including without limitation the rights 9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the Software is 11 | // furnished to do so, subject to the following conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be included in 14 | // all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | // THE SOFTWARE. 23 | // 24 | 25 | #if os(OSX) 26 | import AppKit 27 | #else 28 | import UIKit 29 | #endif 30 | 31 | public extension Constrainable { 32 | 33 | @discardableResult 34 | func center(in view: Constrainable, offset: CGPoint = .zero, priority: LayoutPriority = .required, isActive: Bool = true) -> Constraints { 35 | prepareForLayout() 36 | 37 | let constraints = [ 38 | centerX(to: view, offset: offset.x, priority: priority, isActive: isActive), 39 | centerY(to: view, offset: offset.y, priority: priority, isActive: isActive) 40 | ] 41 | 42 | return constraints 43 | } 44 | 45 | @discardableResult 46 | func edges(to view: Constrainable, excluding excludedEdge: LayoutEdge = .none, insets: TinyEdgeInsets = .zero, relation: ConstraintRelation = .equal, priority: LayoutPriority = .required, isActive: Bool = true) -> Constraints { 47 | prepareForLayout() 48 | 49 | var constraints = Constraints() 50 | 51 | if !excludedEdge.contains(.top) { 52 | constraints.append(top(to: view, offset: insets.top, relation: relation, priority: priority, isActive: isActive)) 53 | } 54 | 55 | if !excludedEdge.contains(.left) { 56 | constraints.append(left(to: view, offset: insets.left, relation: relation, priority: priority, isActive: isActive)) 57 | } 58 | 59 | if !excludedEdge.contains(.bottom) { 60 | constraints.append(bottom(to: view, offset: -insets.bottom, relation: relation, priority: priority, isActive: isActive)) 61 | } 62 | 63 | if !excludedEdge.contains(.right) { 64 | constraints.append(right(to: view, offset: -insets.right, relation: relation, priority: priority, isActive: isActive)) 65 | } 66 | 67 | return constraints 68 | } 69 | 70 | @discardableResult 71 | func size(_ size: CGSize, relation: ConstraintRelation = .equal, priority: LayoutPriority = .required, isActive: Bool = true) -> Constraints { 72 | prepareForLayout() 73 | 74 | let constraints = [ 75 | width(size.width, relation: relation, priority: priority, isActive: isActive), 76 | height(size.height, relation: relation, priority: priority, isActive: isActive) 77 | ] 78 | 79 | return constraints 80 | } 81 | 82 | @discardableResult 83 | func size(to view: Constrainable, multiplier: CGFloat = 1, insets: CGSize = .zero, relation: ConstraintRelation = .equal, priority: LayoutPriority = .required, isActive: Bool = true) -> Constraints { 84 | prepareForLayout() 85 | 86 | let constraints = [ 87 | width(to: view, multiplier: multiplier, offset: insets.width, relation: relation, priority: priority, isActive: isActive), 88 | height(to: view, multiplier: multiplier, offset: insets.height, relation: relation, priority: priority, isActive: isActive) 89 | ] 90 | 91 | return constraints 92 | } 93 | 94 | @discardableResult 95 | func origin(to view: Constrainable, insets: TinyEdgeInsets = .zero, relation: ConstraintRelation = .equal, priority: LayoutPriority = .required, isActive: Bool = true) -> Constraints { 96 | prepareForLayout() 97 | 98 | let constraints = [ 99 | left(to: view, offset: insets.left, relation: relation, priority: priority, isActive: isActive), 100 | top(to: view, offset: insets.top, relation: relation, priority: priority, isActive: isActive) 101 | ] 102 | 103 | return constraints 104 | } 105 | 106 | @discardableResult 107 | func width(_ width: CGFloat, relation: ConstraintRelation = .equal, priority: LayoutPriority = .required, isActive: Bool = true) -> Constraint { 108 | prepareForLayout() 109 | 110 | switch relation { 111 | case .equal: return widthAnchor.constraint(equalToConstant: width).with(priority).set(isActive) 112 | case .equalOrLess: return widthAnchor.constraint(lessThanOrEqualToConstant: width).with(priority).set(isActive) 113 | case .equalOrGreater: return widthAnchor.constraint(greaterThanOrEqualToConstant: width).with(priority).set(isActive) 114 | } 115 | } 116 | 117 | @discardableResult 118 | func width(to view: Constrainable, _ dimension: NSLayoutDimension? = nil, multiplier: CGFloat = 1, offset: CGFloat = 0, relation: ConstraintRelation = .equal, priority: LayoutPriority = .required, isActive: Bool = true) -> Constraint { 119 | prepareForLayout() 120 | 121 | switch relation { 122 | case .equal: return widthAnchor.constraint(equalTo: dimension ?? view.widthAnchor, multiplier: multiplier, constant: offset).with(priority).set(isActive) 123 | case .equalOrLess: return widthAnchor.constraint(lessThanOrEqualTo: dimension ?? view.widthAnchor, multiplier: multiplier, constant: offset).with(priority).set(isActive) 124 | case .equalOrGreater: return widthAnchor.constraint(greaterThanOrEqualTo: dimension ?? view.widthAnchor, multiplier: multiplier, constant: offset).with(priority).set(isActive) 125 | } 126 | } 127 | 128 | @discardableResult 129 | func widthToHeight(of view: Constrainable, multiplier: CGFloat = 1, offset: CGFloat = 0, relation: ConstraintRelation = .equal, priority: LayoutPriority = .required, isActive: Bool = true) -> Constraint { 130 | return width(to: view, view.heightAnchor, multiplier: multiplier, offset: offset, relation: relation, priority: priority, isActive: isActive) 131 | } 132 | 133 | @discardableResult 134 | func width(min: CGFloat? = nil, max: CGFloat? = nil, priority: LayoutPriority = .required, isActive: Bool = true) -> Constraints { 135 | prepareForLayout() 136 | 137 | var constraints: Constraints = [] 138 | 139 | if let min = min { 140 | let constraint = widthAnchor.constraint(greaterThanOrEqualToConstant: min).with(priority) 141 | constraint.isActive = isActive 142 | constraints.append(constraint) 143 | } 144 | 145 | if let max = max { 146 | let constraint = widthAnchor.constraint(lessThanOrEqualToConstant: max).with(priority) 147 | constraint.isActive = isActive 148 | constraints.append(constraint) 149 | } 150 | 151 | return constraints 152 | } 153 | 154 | @discardableResult 155 | func height(_ height: CGFloat, relation: ConstraintRelation = .equal, priority: LayoutPriority = .required, isActive: Bool = true) -> Constraint { 156 | prepareForLayout() 157 | 158 | switch relation { 159 | case .equal: return heightAnchor.constraint(equalToConstant: height).with(priority).set(isActive) 160 | case .equalOrLess: return heightAnchor.constraint(lessThanOrEqualToConstant: height).with(priority).set(isActive) 161 | case .equalOrGreater: return heightAnchor.constraint(greaterThanOrEqualToConstant: height).with(priority).set(isActive) 162 | } 163 | } 164 | 165 | @discardableResult 166 | func height(to view: Constrainable, _ dimension: NSLayoutDimension? = nil, multiplier: CGFloat = 1, offset: CGFloat = 0, relation: ConstraintRelation = .equal, priority: LayoutPriority = .required, isActive: Bool = true) -> Constraint { 167 | prepareForLayout() 168 | 169 | switch relation { 170 | case .equal: return heightAnchor.constraint(equalTo: dimension ?? view.heightAnchor, multiplier: multiplier, constant: offset).with(priority).set(isActive) 171 | case .equalOrLess: return heightAnchor.constraint(lessThanOrEqualTo: dimension ?? view.heightAnchor, multiplier: multiplier, constant: offset).with(priority).set(isActive) 172 | case .equalOrGreater: return heightAnchor.constraint(greaterThanOrEqualTo: dimension ?? view.heightAnchor, multiplier: multiplier, constant: offset).with(priority).set(isActive) 173 | } 174 | } 175 | 176 | @discardableResult 177 | func heightToWidth(of view: Constrainable, multiplier: CGFloat = 1, offset: CGFloat = 0, relation: ConstraintRelation = .equal, priority: LayoutPriority = .required, isActive: Bool = true) -> Constraint { 178 | return height(to: view, view.widthAnchor, multiplier: multiplier, offset: offset, relation: relation, priority: priority, isActive: isActive) 179 | } 180 | 181 | @discardableResult 182 | func height(min: CGFloat? = nil, max: CGFloat? = nil, priority: LayoutPriority = .required, isActive: Bool = true) -> Constraints { 183 | prepareForLayout() 184 | 185 | var constraints: Constraints = [] 186 | 187 | if let min = min { 188 | let constraint = heightAnchor.constraint(greaterThanOrEqualToConstant: min).with(priority) 189 | constraint.isActive = isActive 190 | constraints.append(constraint) 191 | } 192 | 193 | if let max = max { 194 | let constraint = heightAnchor.constraint(lessThanOrEqualToConstant: max).with(priority) 195 | constraint.isActive = isActive 196 | constraints.append(constraint) 197 | } 198 | 199 | return constraints 200 | } 201 | 202 | @discardableResult 203 | func aspectRatio(_ ratio: CGFloat, relation: ConstraintRelation = .equal, priority: LayoutPriority = .required, isActive: Bool = true) -> Constraint { 204 | return widthToHeight(of: self, multiplier: ratio, offset: 0, relation: relation, priority: priority, isActive: isActive) 205 | } 206 | 207 | @discardableResult 208 | func leadingToTrailing(of view: Constrainable, offset: CGFloat = 0, relation: ConstraintRelation = .equal, priority: LayoutPriority = .required, isActive: Bool = true) -> Constraint { 209 | prepareForLayout() 210 | return leading(to: view, view.trailingAnchor, offset: offset, relation: relation, priority: priority, isActive: isActive) 211 | } 212 | 213 | @discardableResult 214 | func leading(to view: Constrainable, _ anchor: NSLayoutXAxisAnchor? = nil, offset: CGFloat = 0, relation: ConstraintRelation = .equal, priority: LayoutPriority = .required, isActive: Bool = true) -> Constraint { 215 | prepareForLayout() 216 | 217 | switch relation { 218 | case .equal: return leadingAnchor.constraint(equalTo: anchor ?? view.leadingAnchor, constant: offset).with(priority).set(isActive) 219 | case .equalOrLess: return leadingAnchor.constraint(lessThanOrEqualTo: anchor ?? view.leadingAnchor, constant: offset).with(priority).set(isActive) 220 | case .equalOrGreater: return leadingAnchor.constraint(greaterThanOrEqualTo: anchor ?? view.leadingAnchor, constant: offset).with(priority).set(isActive) 221 | } 222 | } 223 | 224 | @discardableResult 225 | func leftToRight(of view: Constrainable, offset: CGFloat = 0, relation: ConstraintRelation = .equal, priority: LayoutPriority = .required, isActive: Bool = true) -> Constraint { 226 | prepareForLayout() 227 | return left(to: view, view.rightAnchor, offset: offset, relation: relation, priority: priority, isActive: isActive) 228 | } 229 | 230 | @discardableResult 231 | func left(to view: Constrainable, _ anchor: NSLayoutXAxisAnchor? = nil, offset: CGFloat = 0, relation: ConstraintRelation = .equal, priority: LayoutPriority = .required, isActive: Bool = true) -> Constraint { 232 | prepareForLayout() 233 | 234 | switch relation { 235 | case .equal: return leftAnchor.constraint(equalTo: anchor ?? view.leftAnchor, constant: offset).with(priority).set(isActive) 236 | case .equalOrLess: return leftAnchor.constraint(lessThanOrEqualTo: anchor ?? view.leftAnchor, constant: offset).with(priority).set(isActive) 237 | case .equalOrGreater: return leftAnchor.constraint(greaterThanOrEqualTo: anchor ?? view.leftAnchor, constant: offset).with(priority).set(isActive) 238 | } 239 | } 240 | 241 | @discardableResult 242 | func trailingToLeading(of view: Constrainable, offset: CGFloat = 0, relation: ConstraintRelation = .equal, priority: LayoutPriority = .required, isActive: Bool = true) -> Constraint { 243 | prepareForLayout() 244 | return trailing(to: view, view.leadingAnchor, offset: offset, relation: relation, priority: priority, isActive: isActive) 245 | } 246 | 247 | @discardableResult 248 | func trailing(to view: Constrainable, _ anchor: NSLayoutXAxisAnchor? = nil, offset: CGFloat = 0, relation: ConstraintRelation = .equal, priority: LayoutPriority = .required, isActive: Bool = true) -> Constraint { 249 | prepareForLayout() 250 | 251 | switch relation { 252 | case .equal: return trailingAnchor.constraint(equalTo: anchor ?? view.trailingAnchor, constant: offset).with(priority).set(isActive) 253 | case .equalOrLess: return trailingAnchor.constraint(lessThanOrEqualTo: anchor ?? view.trailingAnchor, constant: offset).with(priority).set(isActive) 254 | case .equalOrGreater: return trailingAnchor.constraint(greaterThanOrEqualTo: anchor ?? view.trailingAnchor, constant: offset).with(priority).set(isActive) 255 | } 256 | } 257 | 258 | @discardableResult 259 | func rightToLeft(of view: Constrainable, offset: CGFloat = 0, relation: ConstraintRelation = .equal, priority: LayoutPriority = .required, isActive: Bool = true) -> Constraint { 260 | prepareForLayout() 261 | return right(to: view, view.leftAnchor, offset: offset, relation: relation, priority: priority, isActive: isActive) 262 | } 263 | 264 | @discardableResult 265 | func right(to view: Constrainable, _ anchor: NSLayoutXAxisAnchor? = nil, offset: CGFloat = 0, relation: ConstraintRelation = .equal, priority: LayoutPriority = .required, isActive: Bool = true) -> Constraint { 266 | prepareForLayout() 267 | 268 | switch relation { 269 | case .equal: return rightAnchor.constraint(equalTo: anchor ?? view.rightAnchor, constant: offset).with(priority).set(isActive) 270 | case .equalOrLess: return rightAnchor.constraint(lessThanOrEqualTo: anchor ?? view.rightAnchor, constant: offset).with(priority).set(isActive) 271 | case .equalOrGreater: return rightAnchor.constraint(greaterThanOrEqualTo: anchor ?? view.rightAnchor, constant: offset).with(priority).set(isActive) 272 | } 273 | } 274 | 275 | @discardableResult 276 | func topToBottom(of view: Constrainable, offset: CGFloat = 0, relation: ConstraintRelation = .equal, priority: LayoutPriority = .required, isActive: Bool = true) -> Constraint { 277 | prepareForLayout() 278 | return top(to: view, view.bottomAnchor, offset: offset, relation: relation, priority: priority, isActive: isActive) 279 | } 280 | 281 | @discardableResult 282 | func top(to view: Constrainable, _ anchor: NSLayoutYAxisAnchor? = nil, offset: CGFloat = 0, relation: ConstraintRelation = .equal, priority: LayoutPriority = .required, isActive: Bool = true) -> Constraint { 283 | prepareForLayout() 284 | 285 | switch relation { 286 | case .equal: return topAnchor.constraint(equalTo: anchor ?? view.topAnchor, constant: offset).with(priority).set(isActive) 287 | case .equalOrLess: return topAnchor.constraint(lessThanOrEqualTo: anchor ?? view.topAnchor, constant: offset).with(priority).set(isActive) 288 | case .equalOrGreater: return topAnchor.constraint(greaterThanOrEqualTo: anchor ?? view.topAnchor, constant: offset).with(priority).set(isActive) 289 | } 290 | } 291 | 292 | @discardableResult 293 | func bottomToTop(of view: Constrainable, offset: CGFloat = 0, relation: ConstraintRelation = .equal, priority: LayoutPriority = .required, isActive: Bool = true) -> Constraint { 294 | prepareForLayout() 295 | return bottom(to: view, view.topAnchor, offset: offset, relation: relation, priority: priority, isActive: isActive) 296 | } 297 | 298 | @discardableResult 299 | func bottom(to view: Constrainable, _ anchor: NSLayoutYAxisAnchor? = nil, offset: CGFloat = 0, relation: ConstraintRelation = .equal, priority: LayoutPriority = .required, isActive: Bool = true) -> Constraint { 300 | prepareForLayout() 301 | 302 | switch relation { 303 | case .equal: return bottomAnchor.constraint(equalTo: anchor ?? view.bottomAnchor, constant: offset).with(priority).set(isActive) 304 | case .equalOrLess: return bottomAnchor.constraint(lessThanOrEqualTo: anchor ?? view.bottomAnchor, constant: offset).with(priority).set(isActive) 305 | case .equalOrGreater: return bottomAnchor.constraint(greaterThanOrEqualTo: anchor ?? view.bottomAnchor, constant: offset).with(priority).set(isActive) 306 | } 307 | } 308 | 309 | @discardableResult 310 | func centerX(to view: Constrainable, _ anchor: NSLayoutXAxisAnchor? = nil, multiplier: CGFloat = 1, offset: CGFloat = 0, priority: LayoutPriority = .required, isActive: Bool = true) -> Constraint { 311 | prepareForLayout() 312 | 313 | let constraint: Constraint 314 | 315 | if let anchor = anchor { 316 | constraint = centerXAnchor.constraint(equalTo: anchor, constant: offset).with(priority) 317 | } else { 318 | constraint = NSLayoutConstraint(item: self, attribute: .centerX, relatedBy: .equal, toItem: view, attribute: .centerX, multiplier: multiplier, constant: offset).with(priority) 319 | } 320 | 321 | constraint.isActive = isActive 322 | return constraint 323 | } 324 | 325 | @discardableResult 326 | func centerY(to view: Constrainable, _ anchor: NSLayoutYAxisAnchor? = nil, multiplier: CGFloat = 1, offset: CGFloat = 0, priority: LayoutPriority = .required, isActive: Bool = true) -> Constraint { 327 | prepareForLayout() 328 | 329 | let constraint: Constraint 330 | 331 | if let anchor = anchor { 332 | constraint = centerYAnchor.constraint(equalTo: anchor, constant: offset).with(priority) 333 | } else { 334 | constraint = NSLayoutConstraint(item: self, attribute: .centerY, relatedBy: .equal, toItem: view, attribute: .centerY, multiplier: multiplier, constant: offset).with(priority) 335 | } 336 | 337 | constraint.isActive = isActive 338 | return constraint 339 | } 340 | } 341 | 342 | public extension TinyView { 343 | 344 | func setHugging(_ priority: LayoutPriority, for axis: ConstraintAxis) { 345 | setContentHuggingPriority(priority, for: axis) 346 | } 347 | 348 | func setCompressionResistance(_ priority: LayoutPriority, for axis: ConstraintAxis) { 349 | setContentCompressionResistancePriority(priority, for: axis) 350 | } 351 | } 352 | -------------------------------------------------------------------------------- /TinyConstraints/Classes/TinyEdgeInsets.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MIT License 3 | // 4 | // Copyright (c) 2017 Robert-Hein Hooijmans 5 | // 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy 7 | // of this software and associated documentation files (the "Software"), to deal 8 | // in the Software without restriction, including without limitation the rights 9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the Software is 11 | // furnished to do so, subject to the following conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be included in 14 | // all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | // THE SOFTWARE. 23 | // 24 | 25 | #if os(OSX) 26 | import AppKit 27 | #else 28 | import UIKit 29 | #endif 30 | 31 | extension TinyEdgeInsets { 32 | 33 | public static func uniform(_ value: CGFloat) -> TinyEdgeInsets { 34 | return TinyEdgeInsets(top: value, left: value, bottom: value, right: value) 35 | } 36 | 37 | public static func top(_ value: CGFloat) -> TinyEdgeInsets { 38 | return TinyEdgeInsets(top: value, left: 0, bottom: 0, right: 0) 39 | } 40 | 41 | public static func left(_ value: CGFloat) -> TinyEdgeInsets { 42 | return TinyEdgeInsets(top: 0, left: value, bottom: 0, right: 0) 43 | } 44 | 45 | public static func bottom(_ value: CGFloat) -> TinyEdgeInsets { 46 | return TinyEdgeInsets(top: 0, left: 0, bottom: value, right: 0) 47 | } 48 | 49 | public static func right(_ value: CGFloat) -> TinyEdgeInsets { 50 | return TinyEdgeInsets(top: 0, left: 0, bottom: 0, right: value) 51 | } 52 | 53 | public static func horizontal(_ value: CGFloat) -> TinyEdgeInsets { 54 | return TinyEdgeInsets(top: 0, left: value, bottom: 0, right: value) 55 | } 56 | 57 | public static func vertical(_ value: CGFloat) -> TinyEdgeInsets { 58 | return TinyEdgeInsets(top: value, left: 0, bottom: value, right: 0) 59 | } 60 | } 61 | 62 | public func + (lhs: TinyEdgeInsets, rhs: TinyEdgeInsets) -> TinyEdgeInsets { 63 | return .init(top: lhs.top + rhs.top, left: lhs.left + rhs.left, bottom: lhs.bottom + rhs.bottom, right: lhs.right + rhs.right) 64 | } 65 | -------------------------------------------------------------------------------- /TinyConstraints/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 3.0.1 19 | CFBundleVersion 20 | $(CURRENT_PROJECT_VERSION) 21 | NSPrincipalClass 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /TinyConstraints/TinyConstraints.h: -------------------------------------------------------------------------------- 1 | // 2 | // MIT License 3 | // 4 | // Copyright (c) 2017 Robert-Hein Hooijmans 5 | // 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy 7 | // of this software and associated documentation files (the "Software"), to deal 8 | // in the Software without restriction, including without limitation the rights 9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the Software is 11 | // furnished to do so, subject to the following conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be included in 14 | // all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | // THE SOFTWARE. 23 | // 24 | 25 | #import 26 | 27 | //! Project version number for TinyConstraints. 28 | FOUNDATION_EXPORT double TinyConstraintsVersionNumber; 29 | 30 | //! Project version string for TinyConstraints. 31 | FOUNDATION_EXPORT const unsigned char TinyConstraintsVersionString[]; 32 | 33 | // In this header, you should import all the public headers of your framework using statements like #import 34 | 35 | 36 | --------------------------------------------------------------------------------