├── .gitignore ├── EEStackLayout.podspec ├── EEStackLayout.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist └── xcuserdata │ └── efekan.egeli.xcuserdatad │ ├── xcdebugger │ └── Breakpoints_v2.xcbkptlist │ └── xcschemes │ └── xcschememanagement.plist ├── EEStackLayout ├── AppDelegate.swift ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── Contents.json ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── Info.plist └── ViewController.swift ├── EEStackLayoutTests └── Info.plist ├── LICENSE ├── Package.swift ├── README.md ├── Sources └── EEStackLayout │ └── EEStackLayout.swift ├── Tests ├── EEStackLayoutTests │ ├── EEStackLayoutTests.swift │ └── XCTestManifests.swift └── LinuxMain.swift └── example1.png /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | /.build 3 | /Packages 4 | /*.xcodeproj 5 | xcuserdata/ 6 | -------------------------------------------------------------------------------- /EEStackLayout.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = 'EEStackLayout' 3 | s.version = '0.1.11' 4 | s.summary = 'A structured vertical/horizontal stackview' 5 | 6 | s.description = <<-DESC 7 | A structured vertical/horizontal stackview which takes subviews with different widths and adds them to its rows/columns depending on the target orientation with paddings, spacings etc. 8 | DESC 9 | 10 | s.homepage = 'https://github.com/efekanegeli/EEStackLayout' 11 | s.license = { :type => 'MIT', :file => 'LICENSE' } 12 | s.author = { 'Efekan Egeli' => 'efekanegeli@gmail.com' } 13 | s.source = { :git => 'https://github.com/efekanegeli/EEStackLayout.git', :tag => s.version.to_s } 14 | 15 | s.ios.deployment_target = '10.0' 16 | s.swift_version = '4.0' 17 | s.source_files = 'Sources/EEStackLayout/EEStackLayout.swift' 18 | 19 | end 20 | -------------------------------------------------------------------------------- /EEStackLayout.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 50; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | E28AED202147A3180077B0A6 /* EEStackLayoutTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E28AED1F2147A3180077B0A6 /* EEStackLayoutTests.swift */; }; 11 | E28AED2A2147A44D0077B0A6 /* EEStackLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = E29F7FFD20C69FC9009316B4 /* EEStackLayout.swift */; }; 12 | E29F7FEA20C69DAE009316B4 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = E29F7FE920C69DAE009316B4 /* AppDelegate.swift */; }; 13 | E29F7FEC20C69DAE009316B4 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E29F7FEB20C69DAE009316B4 /* ViewController.swift */; }; 14 | E29F7FEF20C69DAE009316B4 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = E29F7FED20C69DAE009316B4 /* Main.storyboard */; }; 15 | E29F7FF120C69DB0009316B4 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = E29F7FF020C69DB0009316B4 /* Assets.xcassets */; }; 16 | E29F7FF420C69DB0009316B4 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = E29F7FF220C69DB0009316B4 /* LaunchScreen.storyboard */; }; 17 | E29F7FFE20C69FC9009316B4 /* EEStackLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = E29F7FFD20C69FC9009316B4 /* EEStackLayout.swift */; }; 18 | /* End PBXBuildFile section */ 19 | 20 | /* Begin PBXContainerItemProxy section */ 21 | E28AED222147A3180077B0A6 /* PBXContainerItemProxy */ = { 22 | isa = PBXContainerItemProxy; 23 | containerPortal = E29F7FDE20C69DAE009316B4 /* Project object */; 24 | proxyType = 1; 25 | remoteGlobalIDString = E29F7FE520C69DAE009316B4; 26 | remoteInfo = EEStackLayout; 27 | }; 28 | /* End PBXContainerItemProxy section */ 29 | 30 | /* Begin PBXFileReference section */ 31 | E28AED1D2147A3180077B0A6 /* EEStackLayoutTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = EEStackLayoutTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 32 | E28AED1F2147A3180077B0A6 /* EEStackLayoutTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EEStackLayoutTests.swift; sourceTree = ""; }; 33 | E28AED212147A3180077B0A6 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 34 | E29F7FE620C69DAE009316B4 /* EEStackLayout.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = EEStackLayout.app; sourceTree = BUILT_PRODUCTS_DIR; }; 35 | E29F7FE920C69DAE009316B4 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 36 | E29F7FEB20C69DAE009316B4 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 37 | E29F7FEE20C69DAE009316B4 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 38 | E29F7FF020C69DB0009316B4 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 39 | E29F7FF320C69DB0009316B4 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 40 | E29F7FF520C69DB0009316B4 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 41 | E29F7FFD20C69FC9009316B4 /* EEStackLayout.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EEStackLayout.swift; sourceTree = ""; }; 42 | /* End PBXFileReference section */ 43 | 44 | /* Begin PBXFrameworksBuildPhase section */ 45 | E28AED1A2147A3180077B0A6 /* Frameworks */ = { 46 | isa = PBXFrameworksBuildPhase; 47 | buildActionMask = 2147483647; 48 | files = ( 49 | ); 50 | runOnlyForDeploymentPostprocessing = 0; 51 | }; 52 | E29F7FE320C69DAE009316B4 /* Frameworks */ = { 53 | isa = PBXFrameworksBuildPhase; 54 | buildActionMask = 2147483647; 55 | files = ( 56 | ); 57 | runOnlyForDeploymentPostprocessing = 0; 58 | }; 59 | /* End PBXFrameworksBuildPhase section */ 60 | 61 | /* Begin PBXGroup section */ 62 | E28AED1E2147A3180077B0A6 /* EEStackLayoutTests */ = { 63 | isa = PBXGroup; 64 | children = ( 65 | E28AED1F2147A3180077B0A6 /* EEStackLayoutTests.swift */, 66 | E28AED212147A3180077B0A6 /* Info.plist */, 67 | ); 68 | path = EEStackLayoutTests; 69 | sourceTree = ""; 70 | }; 71 | E29F7FDD20C69DAE009316B4 = { 72 | isa = PBXGroup; 73 | children = ( 74 | E29F7FE820C69DAE009316B4 /* EEStackLayout */, 75 | E28AED1E2147A3180077B0A6 /* EEStackLayoutTests */, 76 | E29F7FE720C69DAE009316B4 /* Products */, 77 | ); 78 | sourceTree = ""; 79 | }; 80 | E29F7FE720C69DAE009316B4 /* Products */ = { 81 | isa = PBXGroup; 82 | children = ( 83 | E29F7FE620C69DAE009316B4 /* EEStackLayout.app */, 84 | E28AED1D2147A3180077B0A6 /* EEStackLayoutTests.xctest */, 85 | ); 86 | name = Products; 87 | sourceTree = ""; 88 | }; 89 | E29F7FE820C69DAE009316B4 /* EEStackLayout */ = { 90 | isa = PBXGroup; 91 | children = ( 92 | E29F7FE920C69DAE009316B4 /* AppDelegate.swift */, 93 | E29F7FEB20C69DAE009316B4 /* ViewController.swift */, 94 | E29F7FFD20C69FC9009316B4 /* EEStackLayout.swift */, 95 | E29F7FED20C69DAE009316B4 /* Main.storyboard */, 96 | E29F7FF020C69DB0009316B4 /* Assets.xcassets */, 97 | E29F7FF220C69DB0009316B4 /* LaunchScreen.storyboard */, 98 | E29F7FF520C69DB0009316B4 /* Info.plist */, 99 | ); 100 | path = EEStackLayout; 101 | sourceTree = ""; 102 | }; 103 | /* End PBXGroup section */ 104 | 105 | /* Begin PBXNativeTarget section */ 106 | E28AED1C2147A3180077B0A6 /* EEStackLayoutTests */ = { 107 | isa = PBXNativeTarget; 108 | buildConfigurationList = E28AED242147A3180077B0A6 /* Build configuration list for PBXNativeTarget "EEStackLayoutTests" */; 109 | buildPhases = ( 110 | E28AED192147A3180077B0A6 /* Sources */, 111 | E28AED1A2147A3180077B0A6 /* Frameworks */, 112 | E28AED1B2147A3180077B0A6 /* Resources */, 113 | ); 114 | buildRules = ( 115 | ); 116 | dependencies = ( 117 | E28AED232147A3180077B0A6 /* PBXTargetDependency */, 118 | ); 119 | name = EEStackLayoutTests; 120 | productName = EEStackLayoutTests; 121 | productReference = E28AED1D2147A3180077B0A6 /* EEStackLayoutTests.xctest */; 122 | productType = "com.apple.product-type.bundle.unit-test"; 123 | }; 124 | E29F7FE520C69DAE009316B4 /* EEStackLayout */ = { 125 | isa = PBXNativeTarget; 126 | buildConfigurationList = E29F7FF820C69DB0009316B4 /* Build configuration list for PBXNativeTarget "EEStackLayout" */; 127 | buildPhases = ( 128 | E29F7FE220C69DAE009316B4 /* Sources */, 129 | E29F7FE320C69DAE009316B4 /* Frameworks */, 130 | E29F7FE420C69DAE009316B4 /* Resources */, 131 | ); 132 | buildRules = ( 133 | ); 134 | dependencies = ( 135 | ); 136 | name = EEStackLayout; 137 | productName = EEStackLayout; 138 | productReference = E29F7FE620C69DAE009316B4 /* EEStackLayout.app */; 139 | productType = "com.apple.product-type.application"; 140 | }; 141 | /* End PBXNativeTarget section */ 142 | 143 | /* Begin PBXProject section */ 144 | E29F7FDE20C69DAE009316B4 /* Project object */ = { 145 | isa = PBXProject; 146 | attributes = { 147 | LastSwiftUpdateCheck = 0940; 148 | LastUpgradeCheck = 0940; 149 | ORGANIZATIONNAME = "Efekan Egeli"; 150 | TargetAttributes = { 151 | E28AED1C2147A3180077B0A6 = { 152 | CreatedOnToolsVersion = 9.4.1; 153 | TestTargetID = E29F7FE520C69DAE009316B4; 154 | }; 155 | E29F7FE520C69DAE009316B4 = { 156 | CreatedOnToolsVersion = 9.4; 157 | }; 158 | }; 159 | }; 160 | buildConfigurationList = E29F7FE120C69DAE009316B4 /* Build configuration list for PBXProject "EEStackLayout" */; 161 | compatibilityVersion = "Xcode 9.3"; 162 | developmentRegion = en; 163 | hasScannedForEncodings = 0; 164 | knownRegions = ( 165 | en, 166 | Base, 167 | ); 168 | mainGroup = E29F7FDD20C69DAE009316B4; 169 | productRefGroup = E29F7FE720C69DAE009316B4 /* Products */; 170 | projectDirPath = ""; 171 | projectRoot = ""; 172 | targets = ( 173 | E29F7FE520C69DAE009316B4 /* EEStackLayout */, 174 | E28AED1C2147A3180077B0A6 /* EEStackLayoutTests */, 175 | ); 176 | }; 177 | /* End PBXProject section */ 178 | 179 | /* Begin PBXResourcesBuildPhase section */ 180 | E28AED1B2147A3180077B0A6 /* Resources */ = { 181 | isa = PBXResourcesBuildPhase; 182 | buildActionMask = 2147483647; 183 | files = ( 184 | ); 185 | runOnlyForDeploymentPostprocessing = 0; 186 | }; 187 | E29F7FE420C69DAE009316B4 /* Resources */ = { 188 | isa = PBXResourcesBuildPhase; 189 | buildActionMask = 2147483647; 190 | files = ( 191 | E29F7FF420C69DB0009316B4 /* LaunchScreen.storyboard in Resources */, 192 | E29F7FF120C69DB0009316B4 /* Assets.xcassets in Resources */, 193 | E29F7FEF20C69DAE009316B4 /* Main.storyboard in Resources */, 194 | ); 195 | runOnlyForDeploymentPostprocessing = 0; 196 | }; 197 | /* End PBXResourcesBuildPhase section */ 198 | 199 | /* Begin PBXSourcesBuildPhase section */ 200 | E28AED192147A3180077B0A6 /* Sources */ = { 201 | isa = PBXSourcesBuildPhase; 202 | buildActionMask = 2147483647; 203 | files = ( 204 | E28AED202147A3180077B0A6 /* EEStackLayoutTests.swift in Sources */, 205 | E28AED2A2147A44D0077B0A6 /* EEStackLayout.swift in Sources */, 206 | ); 207 | runOnlyForDeploymentPostprocessing = 0; 208 | }; 209 | E29F7FE220C69DAE009316B4 /* Sources */ = { 210 | isa = PBXSourcesBuildPhase; 211 | buildActionMask = 2147483647; 212 | files = ( 213 | E29F7FEC20C69DAE009316B4 /* ViewController.swift in Sources */, 214 | E29F7FEA20C69DAE009316B4 /* AppDelegate.swift in Sources */, 215 | E29F7FFE20C69FC9009316B4 /* EEStackLayout.swift in Sources */, 216 | ); 217 | runOnlyForDeploymentPostprocessing = 0; 218 | }; 219 | /* End PBXSourcesBuildPhase section */ 220 | 221 | /* Begin PBXTargetDependency section */ 222 | E28AED232147A3180077B0A6 /* PBXTargetDependency */ = { 223 | isa = PBXTargetDependency; 224 | target = E29F7FE520C69DAE009316B4 /* EEStackLayout */; 225 | targetProxy = E28AED222147A3180077B0A6 /* PBXContainerItemProxy */; 226 | }; 227 | /* End PBXTargetDependency section */ 228 | 229 | /* Begin PBXVariantGroup section */ 230 | E29F7FED20C69DAE009316B4 /* Main.storyboard */ = { 231 | isa = PBXVariantGroup; 232 | children = ( 233 | E29F7FEE20C69DAE009316B4 /* Base */, 234 | ); 235 | name = Main.storyboard; 236 | sourceTree = ""; 237 | }; 238 | E29F7FF220C69DB0009316B4 /* LaunchScreen.storyboard */ = { 239 | isa = PBXVariantGroup; 240 | children = ( 241 | E29F7FF320C69DB0009316B4 /* Base */, 242 | ); 243 | name = LaunchScreen.storyboard; 244 | sourceTree = ""; 245 | }; 246 | /* End PBXVariantGroup section */ 247 | 248 | /* Begin XCBuildConfiguration section */ 249 | E28AED252147A3180077B0A6 /* Debug */ = { 250 | isa = XCBuildConfiguration; 251 | buildSettings = { 252 | BUNDLE_LOADER = "$(TEST_HOST)"; 253 | CODE_SIGN_STYLE = Automatic; 254 | DEVELOPMENT_TEAM = D6D5362XU9; 255 | INFOPLIST_FILE = EEStackLayoutTests/Info.plist; 256 | LD_RUNPATH_SEARCH_PATHS = ( 257 | "$(inherited)", 258 | "@executable_path/Frameworks", 259 | "@loader_path/Frameworks", 260 | ); 261 | PRODUCT_BUNDLE_IDENTIFIER = ss.EEStackLayoutTests; 262 | PRODUCT_NAME = "$(TARGET_NAME)"; 263 | SWIFT_VERSION = 4.0; 264 | TARGETED_DEVICE_FAMILY = "1,2"; 265 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/EEStackLayout.app/EEStackLayout"; 266 | }; 267 | name = Debug; 268 | }; 269 | E28AED262147A3180077B0A6 /* Release */ = { 270 | isa = XCBuildConfiguration; 271 | buildSettings = { 272 | BUNDLE_LOADER = "$(TEST_HOST)"; 273 | CODE_SIGN_STYLE = Automatic; 274 | DEVELOPMENT_TEAM = D6D5362XU9; 275 | INFOPLIST_FILE = EEStackLayoutTests/Info.plist; 276 | LD_RUNPATH_SEARCH_PATHS = ( 277 | "$(inherited)", 278 | "@executable_path/Frameworks", 279 | "@loader_path/Frameworks", 280 | ); 281 | PRODUCT_BUNDLE_IDENTIFIER = ss.EEStackLayoutTests; 282 | PRODUCT_NAME = "$(TARGET_NAME)"; 283 | SWIFT_VERSION = 4.0; 284 | TARGETED_DEVICE_FAMILY = "1,2"; 285 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/EEStackLayout.app/EEStackLayout"; 286 | }; 287 | name = Release; 288 | }; 289 | E29F7FF620C69DB0009316B4 /* Debug */ = { 290 | isa = XCBuildConfiguration; 291 | buildSettings = { 292 | ALWAYS_SEARCH_USER_PATHS = NO; 293 | CLANG_ANALYZER_NONNULL = YES; 294 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 295 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 296 | CLANG_CXX_LIBRARY = "libc++"; 297 | CLANG_ENABLE_MODULES = YES; 298 | CLANG_ENABLE_OBJC_ARC = YES; 299 | CLANG_ENABLE_OBJC_WEAK = YES; 300 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 301 | CLANG_WARN_BOOL_CONVERSION = YES; 302 | CLANG_WARN_COMMA = YES; 303 | CLANG_WARN_CONSTANT_CONVERSION = YES; 304 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 305 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 306 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 307 | CLANG_WARN_EMPTY_BODY = YES; 308 | CLANG_WARN_ENUM_CONVERSION = YES; 309 | CLANG_WARN_INFINITE_RECURSION = YES; 310 | CLANG_WARN_INT_CONVERSION = YES; 311 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 312 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 313 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 314 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 315 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 316 | CLANG_WARN_STRICT_PROTOTYPES = YES; 317 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 318 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 319 | CLANG_WARN_UNREACHABLE_CODE = YES; 320 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 321 | CODE_SIGN_IDENTITY = "iPhone Developer"; 322 | COPY_PHASE_STRIP = NO; 323 | DEBUG_INFORMATION_FORMAT = dwarf; 324 | ENABLE_STRICT_OBJC_MSGSEND = YES; 325 | ENABLE_TESTABILITY = YES; 326 | GCC_C_LANGUAGE_STANDARD = gnu11; 327 | GCC_DYNAMIC_NO_PIC = NO; 328 | GCC_NO_COMMON_BLOCKS = YES; 329 | GCC_OPTIMIZATION_LEVEL = 0; 330 | GCC_PREPROCESSOR_DEFINITIONS = ( 331 | "DEBUG=1", 332 | "$(inherited)", 333 | ); 334 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 335 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 336 | GCC_WARN_UNDECLARED_SELECTOR = YES; 337 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 338 | GCC_WARN_UNUSED_FUNCTION = YES; 339 | GCC_WARN_UNUSED_VARIABLE = YES; 340 | IPHONEOS_DEPLOYMENT_TARGET = 11.4; 341 | MTL_ENABLE_DEBUG_INFO = YES; 342 | ONLY_ACTIVE_ARCH = YES; 343 | SDKROOT = iphoneos; 344 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 345 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 346 | }; 347 | name = Debug; 348 | }; 349 | E29F7FF720C69DB0009316B4 /* Release */ = { 350 | isa = XCBuildConfiguration; 351 | buildSettings = { 352 | ALWAYS_SEARCH_USER_PATHS = NO; 353 | CLANG_ANALYZER_NONNULL = YES; 354 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 355 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 356 | CLANG_CXX_LIBRARY = "libc++"; 357 | CLANG_ENABLE_MODULES = YES; 358 | CLANG_ENABLE_OBJC_ARC = YES; 359 | CLANG_ENABLE_OBJC_WEAK = YES; 360 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 361 | CLANG_WARN_BOOL_CONVERSION = YES; 362 | CLANG_WARN_COMMA = YES; 363 | CLANG_WARN_CONSTANT_CONVERSION = YES; 364 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 365 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 366 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 367 | CLANG_WARN_EMPTY_BODY = YES; 368 | CLANG_WARN_ENUM_CONVERSION = YES; 369 | CLANG_WARN_INFINITE_RECURSION = YES; 370 | CLANG_WARN_INT_CONVERSION = YES; 371 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 372 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 373 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 374 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 375 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 376 | CLANG_WARN_STRICT_PROTOTYPES = YES; 377 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 378 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 379 | CLANG_WARN_UNREACHABLE_CODE = YES; 380 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 381 | CODE_SIGN_IDENTITY = "iPhone Developer"; 382 | COPY_PHASE_STRIP = NO; 383 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 384 | ENABLE_NS_ASSERTIONS = NO; 385 | ENABLE_STRICT_OBJC_MSGSEND = YES; 386 | GCC_C_LANGUAGE_STANDARD = gnu11; 387 | GCC_NO_COMMON_BLOCKS = YES; 388 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 389 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 390 | GCC_WARN_UNDECLARED_SELECTOR = YES; 391 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 392 | GCC_WARN_UNUSED_FUNCTION = YES; 393 | GCC_WARN_UNUSED_VARIABLE = YES; 394 | IPHONEOS_DEPLOYMENT_TARGET = 11.4; 395 | MTL_ENABLE_DEBUG_INFO = NO; 396 | SDKROOT = iphoneos; 397 | SWIFT_COMPILATION_MODE = wholemodule; 398 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 399 | VALIDATE_PRODUCT = YES; 400 | }; 401 | name = Release; 402 | }; 403 | E29F7FF920C69DB0009316B4 /* Debug */ = { 404 | isa = XCBuildConfiguration; 405 | buildSettings = { 406 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 407 | CODE_SIGN_STYLE = Automatic; 408 | DEVELOPMENT_TEAM = D6D5362XU9; 409 | INFOPLIST_FILE = EEStackLayout/Info.plist; 410 | LD_RUNPATH_SEARCH_PATHS = ( 411 | "$(inherited)", 412 | "@executable_path/Frameworks", 413 | ); 414 | PRODUCT_BUNDLE_IDENTIFIER = efekanegeli.EEStackLayout; 415 | PRODUCT_NAME = "$(TARGET_NAME)"; 416 | SWIFT_VERSION = 4.0; 417 | TARGETED_DEVICE_FAMILY = "1,2"; 418 | }; 419 | name = Debug; 420 | }; 421 | E29F7FFA20C69DB0009316B4 /* Release */ = { 422 | isa = XCBuildConfiguration; 423 | buildSettings = { 424 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 425 | CODE_SIGN_STYLE = Automatic; 426 | DEVELOPMENT_TEAM = D6D5362XU9; 427 | INFOPLIST_FILE = EEStackLayout/Info.plist; 428 | LD_RUNPATH_SEARCH_PATHS = ( 429 | "$(inherited)", 430 | "@executable_path/Frameworks", 431 | ); 432 | PRODUCT_BUNDLE_IDENTIFIER = efekanegeli.EEStackLayout; 433 | PRODUCT_NAME = "$(TARGET_NAME)"; 434 | SWIFT_VERSION = 4.0; 435 | TARGETED_DEVICE_FAMILY = "1,2"; 436 | }; 437 | name = Release; 438 | }; 439 | /* End XCBuildConfiguration section */ 440 | 441 | /* Begin XCConfigurationList section */ 442 | E28AED242147A3180077B0A6 /* Build configuration list for PBXNativeTarget "EEStackLayoutTests" */ = { 443 | isa = XCConfigurationList; 444 | buildConfigurations = ( 445 | E28AED252147A3180077B0A6 /* Debug */, 446 | E28AED262147A3180077B0A6 /* Release */, 447 | ); 448 | defaultConfigurationIsVisible = 0; 449 | defaultConfigurationName = Release; 450 | }; 451 | E29F7FE120C69DAE009316B4 /* Build configuration list for PBXProject "EEStackLayout" */ = { 452 | isa = XCConfigurationList; 453 | buildConfigurations = ( 454 | E29F7FF620C69DB0009316B4 /* Debug */, 455 | E29F7FF720C69DB0009316B4 /* Release */, 456 | ); 457 | defaultConfigurationIsVisible = 0; 458 | defaultConfigurationName = Release; 459 | }; 460 | E29F7FF820C69DB0009316B4 /* Build configuration list for PBXNativeTarget "EEStackLayout" */ = { 461 | isa = XCConfigurationList; 462 | buildConfigurations = ( 463 | E29F7FF920C69DB0009316B4 /* Debug */, 464 | E29F7FFA20C69DB0009316B4 /* Release */, 465 | ); 466 | defaultConfigurationIsVisible = 0; 467 | defaultConfigurationName = Release; 468 | }; 469 | /* End XCConfigurationList section */ 470 | }; 471 | rootObject = E29F7FDE20C69DAE009316B4 /* Project object */; 472 | } 473 | -------------------------------------------------------------------------------- /EEStackLayout.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /EEStackLayout.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /EEStackLayout.xcodeproj/xcuserdata/efekan.egeli.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /EEStackLayout.xcodeproj/xcuserdata/efekan.egeli.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | EEStackLayout.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | EEStackLayout.xcscheme_^#shared#^_ 13 | 14 | orderHint 15 | 0 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /EEStackLayout/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // EEStackLayout 4 | // 5 | // Created by Efekan Egeli on 5.06.2018. 6 | // Copyright © 2018 Efekan Egeli. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 18 | // Override point for customization after application launch. 19 | return true 20 | } 21 | 22 | func applicationWillResignActive(_ application: UIApplication) { 23 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 24 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 25 | } 26 | 27 | func applicationDidEnterBackground(_ application: UIApplication) { 28 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 30 | } 31 | 32 | func applicationWillEnterForeground(_ application: UIApplication) { 33 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 34 | } 35 | 36 | func applicationDidBecomeActive(_ application: UIApplication) { 37 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 38 | } 39 | 40 | func applicationWillTerminate(_ application: UIApplication) { 41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 42 | } 43 | 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /EEStackLayout/Assets.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 | } -------------------------------------------------------------------------------- /EEStackLayout/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /EEStackLayout/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /EEStackLayout/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /EEStackLayout/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 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 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UILaunchStoryboardName 24 | LaunchScreen 25 | UIMainStoryboardFile 26 | Main 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | UISupportedInterfaceOrientations~ipad 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /EEStackLayout/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // EEStackLayout 4 | // 5 | // Created by Efekan Egeli on 5.06.2018. 6 | // Copyright © 2018 Efekan Egeli. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ViewController: UIViewController { 12 | 13 | override func viewDidLoad() { 14 | super.viewDidLoad() 15 | // Do any additional setup after loading the view, typically from a nib. 16 | 17 | self.view.backgroundColor = .orange 18 | 19 | // Subviews that will be added to stack layout 20 | var viewArray = [UIView]() 21 | 22 | // Choose the orientation of EEStackLayout -> vertical / horizontal [Just for demo purposes, change it if you want to see how horizontal EEStackLayout works] 23 | let targetOrientationOfStackLayout = NSLayoutConstraint.Axis.vertical 24 | 25 | let stackLayout: EEStackLayout 26 | 27 | if targetOrientationOfStackLayout == .vertical { 28 | // Vertical EEStackLayout 29 | 30 | // Views with same height for the vertical layout 31 | for _ in 1...25 { 32 | let view1 = UIView(frame: CGRect(x: 0, y: 0, width: 20, height: 42)) 33 | view1.backgroundColor = .green 34 | let view2 = UIView(frame: CGRect(x: 0, y: 0, width: 30, height: 42)) 35 | view2.backgroundColor = .blue 36 | let view3 = UIView(frame: CGRect(x: 0, y: 0, width: 40, height: 42)) 37 | view3.backgroundColor = .yellow 38 | let view4 = UIView(frame: CGRect(x: 0, y: 0, width: 50, height: 42)) 39 | view4.backgroundColor = .black 40 | viewArray.append(view1) 41 | viewArray.append(view2) 42 | viewArray.append(view3) 43 | viewArray.append(view4) 44 | } 45 | 46 | // Vertical EEStackLayout setup 47 | stackLayout = EEStackLayout(frame: CGRect(x: 0, y: 50, width: 300, height: 0), 48 | rowHeight: 20, 49 | minimumInteritemSpacing: 15, 50 | minimumItemSpacing: 10, 51 | insets: UIEdgeInsets(top: 15, left: 15, bottom: 15, right: 15), 52 | subviews: viewArray) 53 | 54 | } else { 55 | // Horizontal EEStackLayout 56 | 57 | // Views with same width for the horizontal layout 58 | for _ in 1...25 { 59 | let view1 = UIView(frame: CGRect(x: 0, y: 0, width: 30, height: 15)) 60 | view1.backgroundColor = .green 61 | let view2 = UIView(frame: CGRect(x: 0, y: 0, width: 30, height: 25)) 62 | view2.backgroundColor = .blue 63 | let view3 = UIView(frame: CGRect(x: 0, y: 0, width: 30, height: 35)) 64 | view3.backgroundColor = .yellow 65 | let view4 = UIView(frame: CGRect(x: 0, y: 0, width: 30, height: 45)) 66 | view4.backgroundColor = .black 67 | viewArray.append(view1) 68 | viewArray.append(view2) 69 | viewArray.append(view3) 70 | viewArray.append(view4) 71 | } 72 | 73 | // Horizontal EEStackLayout setup 74 | stackLayout = EEStackLayout(frame: CGRect(x: 0, y: 50, width: 0, height: 400), 75 | columnWidth: 20, 76 | minimumInteritemSpacing: 15, 77 | minimumItemSpacing: 10, 78 | insets: UIEdgeInsets(top: 15, left: 15, bottom: 15, right: 15), 79 | subviews: viewArray) 80 | } 81 | 82 | self.view.addSubview(stackLayout) 83 | } 84 | 85 | override func didReceiveMemoryWarning() { 86 | super.didReceiveMemoryWarning() 87 | // Dispose of any resources that can be recreated. 88 | } 89 | 90 | 91 | } 92 | 93 | -------------------------------------------------------------------------------- /EEStackLayoutTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 efekanegeli 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version:5.1 2 | // The swift-tools-version declares the minimum version of Swift required to build this package. 3 | 4 | import PackageDescription 5 | 6 | let package = Package( 7 | name: "EEStackLayout", 8 | platforms: [ 9 | .iOS(.v9), 10 | .tvOS(.v9), 11 | ], 12 | products: [ 13 | // Products define the executables and libraries produced by a package, and make them visible to other packages. 14 | .library( 15 | name: "EEStackLayout", 16 | targets: ["EEStackLayout"]), 17 | ], 18 | dependencies: [ 19 | // Dependencies declare other packages that this package depends on. 20 | // .package(url: /* package url */, from: "1.0.0"), 21 | ], 22 | targets: [ 23 | // Targets are the basic building blocks of a package. A target can define a module or a test suite. 24 | // Targets can depend on other targets in this package, and on products in packages which this package depends on. 25 | .target( 26 | name: "EEStackLayout", 27 | dependencies: []), 28 | .testTarget( 29 | name: "EEStackLayoutTests", 30 | dependencies: ["EEStackLayout"]), 31 | ] 32 | ) 33 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # EEStackLayout 2 | 3 | A vertical stackview which takes subviews with different widths and adds them to it's rows with paddings, spacings etc. 4 | 5 | 6 | [![Twitter: @efekanegeli](https://img.shields.io/badge/contact-%40efekanegeli-blue.svg)](https://twitter.com/efekanegeli) 7 | [![CocoaPods](https://img.shields.io/badge/pod-v0.1.11-blue.svg)](https://github.com/efekanegeli/EEStackLayout) 8 | 9 | ![Screenshot](https://github.com/efekanegeli/EEStackLayout/blob/master/example1.png) 10 | 11 | ## Installation 12 | 13 | ### Cocoapods 14 | 15 | ``` 16 | pod 'EEStackLayout', '~> 0.1' 17 | pod install 18 | ``` 19 | 20 | ### Swift Package Manager 21 | 22 | ``` 23 | .package(url: "https://github.com/efekanegeli/EEStackLayout.git", from: "0.1.11") 24 | ``` 25 | 26 | ### Manual 27 | 28 | ``` 29 | 1. Download .zip file 30 | 2. Just drag and drop EEStackLayout.swift to your project 31 | ``` 32 | 33 | ## Example Usage 34 | 35 | ```swift 36 | // Subviews that will be added to stack layout 37 | var viewArray = [UIView]() 38 | 39 | // Choose the orientation of EEStackLayout -> vertical / horizontal [Just for demo purposes, change it if you want to see how horizontal EEStackLayout works] 40 | let targetOrientationOfStackLayout = NSLayoutConstraint.Axis.vertical 41 | 42 | let stackLayout: EEStackLayout 43 | 44 | if targetOrientationOfStackLayout == .vertical { 45 | // Vertical EEStackLayout 46 | 47 | // Views with same height for the vertical layout 48 | for _ in 1...25 { 49 | let view1 = UIView(frame: CGRect(x: 0, y: 0, width: 20, height: 42)) 50 | view1.backgroundColor = .green 51 | let view2 = UIView(frame: CGRect(x: 0, y: 0, width: 30, height: 42)) 52 | view2.backgroundColor = .blue 53 | let view3 = UIView(frame: CGRect(x: 0, y: 0, width: 40, height: 42)) 54 | view3.backgroundColor = .yellow 55 | let view4 = UIView(frame: CGRect(x: 0, y: 0, width: 50, height: 42)) 56 | view4.backgroundColor = .black 57 | viewArray.append(view1) 58 | viewArray.append(view2) 59 | viewArray.append(view3) 60 | viewArray.append(view4) 61 | } 62 | 63 | // Vertical EEStackLayout setup 64 | stackLayout = EEStackLayout(frame: CGRect(x: 0, y: 50, width: 300, height: 0), 65 | rowHeight: 20, 66 | minimumInteritemSpacing: 15, 67 | minimumItemSpacing: 10, 68 | insets: UIEdgeInsets(top: 15, left: 15, bottom: 15, right: 15), 69 | subviews: viewArray) 70 | 71 | } else { 72 | // Horizontal EEStackLayout 73 | 74 | // Views with same width for the horizontal layout 75 | for _ in 1...25 { 76 | let view1 = UIView(frame: CGRect(x: 0, y: 0, width: 30, height: 15)) 77 | view1.backgroundColor = .green 78 | let view2 = UIView(frame: CGRect(x: 0, y: 0, width: 30, height: 25)) 79 | view2.backgroundColor = .blue 80 | let view3 = UIView(frame: CGRect(x: 0, y: 0, width: 30, height: 35)) 81 | view3.backgroundColor = .yellow 82 | let view4 = UIView(frame: CGRect(x: 0, y: 0, width: 30, height: 45)) 83 | view4.backgroundColor = .black 84 | viewArray.append(view1) 85 | viewArray.append(view2) 86 | viewArray.append(view3) 87 | viewArray.append(view4) 88 | } 89 | 90 | // Horizontal EEStackLayout setup 91 | stackLayout = EEStackLayout(frame: CGRect(x: 0, y: 50, width: 0, height: 400), 92 | columnWidth: 20, 93 | minimumInteritemSpacing: 15, 94 | minimumItemSpacing: 10, 95 | insets: UIEdgeInsets(top: 15, left: 15, bottom: 15, right: 15), 96 | subviews: viewArray) 97 | } 98 | 99 | self.view.addSubview(stackLayout) 100 | ``` 101 | 102 | ## Init Properties 103 | ``` 104 | minimumItemSpacing -> Spacing between rows(vertical layout) or colums(horizontal layout) 105 | rowHeight -> Row height of the main vertical stack view 106 | maximumRowCount -> Maximum row count of the vertical stack view, ignores the rest of the subviews if the actual row count exceeds the limit 107 | columnWidth -> Column width of the main horizontal stack view 108 | maximumColumnCount -> Maximum column count of the horizontal stack view, ignores the rest of the subviews if the actual column count exceeds the limit 109 | minimumInteritemSpacing -> Spacing between items in a row/column 110 | insets -> Layout margins of main vertical stack view 111 | subviews -> View array of elements to be added to the main stack view 112 | ``` 113 | 114 | ## License 115 | 116 | MIT License, Copyright (c) 2018 Efekan Egeli, [@efekanegeli](https://twitter.com/efekanegeli) 117 | -------------------------------------------------------------------------------- /Sources/EEStackLayout/EEStackLayout.swift: -------------------------------------------------------------------------------- 1 | // 2 | // EEStackLayout.swift 3 | // EEStackLayout 4 | // 5 | // Created by Efekan Egeli on 5.06.2018. 6 | // Copyright © 2018 Efekan Egeli. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | open class EEStackLayout: UIStackView { 12 | 13 | // MARK: Private Logical Variables 14 | private var totalSubviewWidth = CGFloat(0) 15 | private var totalSubviewHeight = CGFloat(0) 16 | private var rowView = UIView() 17 | private var columnView = UIView() 18 | private var previousSubview = UIView() 19 | private var totalSubviewWidthWithSpacings = CGFloat(0) 20 | private var totalSubviewHeightWithSpacings = CGFloat(0) 21 | private var maximumColumnCount: Int32 = INT_MAX 22 | private var maximumRowCount: Int32 = INT_MAX 23 | private var rowCount: Int32 = 0 24 | private var columnCount: Int32 = 0 25 | 26 | // MARK: Private UI Related Variables 27 | private var rowHeight: CGFloat = .leastNonzeroMagnitude 28 | private var columnWidth: CGFloat = .leastNonzeroMagnitude 29 | private var orientation: NSLayoutConstraint.Axis = .vertical 30 | private let minimumInteritemSpacing: CGFloat 31 | private let minimumItemSpacing: CGFloat 32 | private let insets: UIEdgeInsets 33 | 34 | // MARK: Initializers 35 | public init(frame: CGRect, 36 | columnWidth: CGFloat? = nil, 37 | maximumColumnCount: Int32? = nil, 38 | rowHeight: CGFloat? = nil, 39 | maximumRowCount: Int32? = nil, 40 | minimumInteritemSpacing: CGFloat, 41 | minimumItemSpacing: CGFloat, 42 | insets: UIEdgeInsets, 43 | subviews: [UIView]) { 44 | if let heightOfEachRow = rowHeight { 45 | self.rowHeight = heightOfEachRow 46 | self.orientation = .vertical 47 | } 48 | if let widthOfEachColumn = columnWidth { 49 | self.columnWidth = widthOfEachColumn 50 | self.orientation = .horizontal 51 | } 52 | if let maxColumnCount = maximumColumnCount { 53 | self.maximumColumnCount = maxColumnCount 54 | } 55 | if let maxRowCount = maximumRowCount { 56 | self.maximumRowCount = maxRowCount 57 | } 58 | 59 | self.minimumInteritemSpacing = minimumInteritemSpacing 60 | self.minimumItemSpacing = minimumItemSpacing 61 | self.insets = insets 62 | super.init(frame: frame) 63 | setupUI(subviews: subviews) 64 | } 65 | 66 | private func setupUI(subviews: [UIView]) { 67 | setupMainStackView() 68 | setupLayout(subviews: subviews) 69 | } 70 | 71 | @available(*, unavailable) 72 | public required init(coder: NSCoder) { 73 | fatalError("init(coder:) has not been implemented") 74 | } 75 | 76 | // MARK: Property Setup 77 | private func setupMainStackView() { 78 | self.alignment = .fill 79 | self.distribution = .fill 80 | self.spacing = minimumItemSpacing 81 | self.axis = orientation 82 | self.layoutMargins = insets 83 | self.isLayoutMarginsRelativeArrangement = true 84 | } 85 | 86 | // MARK: Layout Setup 87 | private func setupLayout(subviews: [UIView]) { 88 | if orientation == .vertical { 89 | addNewRow() 90 | } else { 91 | addNewColumn() 92 | } 93 | 94 | for subview in subviews { 95 | if orientation == .vertical { 96 | if doesSubviewFitInRow(subview: subview) { 97 | addSubviewToRow(subview: subview) 98 | } else if rowCount < maximumRowCount { 99 | addNewRow() 100 | addSubviewToRow(subview: subview) 101 | } 102 | } else { 103 | if doesSubviewFitInColumn(subview: subview) { 104 | addSubviewToColumn(subview: subview) 105 | } else if columnCount < maximumColumnCount { 106 | addNewColumn() 107 | addSubviewToColumn(subview: subview) 108 | } 109 | } 110 | } 111 | 112 | if orientation == .vertical { 113 | let height = (CGFloat(arrangedSubviews.count) * rowHeight) + (CGFloat(arrangedSubviews.count - 1) * minimumItemSpacing) + insets.top + insets.bottom 114 | self.frame = CGRect(x: self.frame.origin.x, y: self.frame.origin.y, width: self.frame.size.width, height: height) 115 | } else { 116 | let width = (CGFloat(arrangedSubviews.count) * columnWidth) + (CGFloat(arrangedSubviews.count - 1) * minimumItemSpacing) + insets.left + insets.right 117 | self.frame = CGRect(x: self.frame.origin.x, y: self.frame.origin.y, width: width, height: self.frame.size.height) 118 | } 119 | } 120 | 121 | // MARK: Row Operations 122 | private func doesSubviewFitInRow(subview: UIView) -> Bool { 123 | totalSubviewWidthWithSpacings = CGFloat(rowView.subviews.count - 1) * minimumInteritemSpacing + totalSubviewWidth 124 | if totalSubviewWidthWithSpacings > 0 && self.frame.size.width - totalSubviewWidthWithSpacings < subview.frame.size.width + minimumInteritemSpacing { 125 | return false 126 | } else { 127 | return true 128 | } 129 | } 130 | 131 | private func addSubviewToRow(subview: UIView) { 132 | subview.translatesAutoresizingMaskIntoConstraints = false 133 | rowView.addSubview(subview) 134 | totalSubviewWidth += subview.frame.size.width 135 | if rowView.subviews.count == 1 { 136 | subview.leadingAnchor.constraint(equalTo: rowView.leadingAnchor, constant: insets.left).isActive = true 137 | } else { 138 | subview.leadingAnchor.constraint(equalTo: previousSubview.trailingAnchor, constant: minimumInteritemSpacing).isActive = true 139 | } 140 | subview.heightAnchor.constraint(equalToConstant: rowHeight).isActive = true 141 | subview.widthAnchor.constraint(equalToConstant: subview.frame.size.width).isActive = true 142 | subview.centerYAnchor.constraint(equalTo: rowView.centerYAnchor).isActive = true 143 | previousSubview = subview 144 | } 145 | 146 | private func addNewRow() { 147 | rowCount += 1 148 | totalSubviewWidth = insets.left + insets.right 149 | rowView = UIView() 150 | rowView.backgroundColor = .clear 151 | rowView.heightAnchor.constraint(equalToConstant: rowHeight).isActive = true 152 | self.addArrangedSubview(rowView) 153 | } 154 | 155 | // MARK: Column Operations 156 | private func doesSubviewFitInColumn(subview: UIView) -> Bool { 157 | totalSubviewHeightWithSpacings = CGFloat(columnView.subviews.count - 1) * minimumInteritemSpacing + totalSubviewHeight 158 | if totalSubviewHeightWithSpacings > 0 && self.frame.size.height - totalSubviewHeightWithSpacings < subview.frame.size.height + minimumInteritemSpacing { 159 | return false 160 | } else { 161 | return true 162 | } 163 | } 164 | 165 | private func addSubviewToColumn(subview: UIView) { 166 | subview.translatesAutoresizingMaskIntoConstraints = false 167 | columnView.addSubview(subview) 168 | totalSubviewHeight += subview.frame.size.height 169 | if columnView.subviews.count == 1 { 170 | subview.topAnchor.constraint(equalTo: columnView.topAnchor, constant: insets.top).isActive = true 171 | } else { 172 | subview.topAnchor.constraint(equalTo: previousSubview.bottomAnchor, constant: minimumInteritemSpacing).isActive = true 173 | } 174 | subview.widthAnchor.constraint(equalToConstant: columnWidth).isActive = true 175 | subview.heightAnchor.constraint(equalToConstant: subview.frame.size.height).isActive = true 176 | subview.centerXAnchor.constraint(equalTo: columnView.centerXAnchor).isActive = true 177 | previousSubview = subview 178 | } 179 | 180 | private func addNewColumn() { 181 | columnCount += 1 182 | totalSubviewHeight = insets.top + insets.bottom 183 | columnView = UIView() 184 | columnView.backgroundColor = .clear 185 | columnView.widthAnchor.constraint(equalToConstant: columnWidth).isActive = true 186 | self.addArrangedSubview(columnView) 187 | } 188 | 189 | // MARK: Public Methods 190 | public func getRowCount() -> Int { 191 | return Int(rowCount) 192 | } 193 | 194 | public func getColumnCount() -> Int { 195 | return Int(columnCount) 196 | } 197 | } 198 | -------------------------------------------------------------------------------- /Tests/EEStackLayoutTests/EEStackLayoutTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // EEStackLayoutTests.swift 3 | // EEStackLayoutTests 4 | // 5 | // Created by Efekan Egeli on 11.09.2018. 6 | // Copyright © 2018 Efekan Egeli. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | 11 | class EEStackLayoutTests: XCTestCase { 12 | var viewArray = [UIView]() 13 | 14 | override func setUp() { 15 | super.setUp() 16 | // Put setup code here. This method is called before the invocation of each test method in the class. 17 | 18 | 19 | 20 | } 21 | 22 | override func tearDown() { 23 | // Put teardown code here. This method is called after the invocation of each test method in the class. 24 | super.tearDown() 25 | } 26 | 27 | func test_seven_lines_stack_layout() { 28 | for _ in 1...5 { 29 | let view1 = UIView(frame: CGRect(x: 0, y: 0, width: 20, height: 42)) 30 | view1.backgroundColor = .green 31 | 32 | let view2 = UIView(frame: CGRect(x: 0, y: 0, width: 30, height: 42)) 33 | view2.backgroundColor = .blue 34 | 35 | let view3 = UIView(frame: CGRect(x: 0, y: 0, width: 40, height: 42)) 36 | view3.backgroundColor = .yellow 37 | 38 | let view4 = UIView(frame: CGRect(x: 0, y: 0, width: 50, height: 42)) 39 | view4.backgroundColor = .black 40 | 41 | viewArray.append(view1) 42 | viewArray.append(view2) 43 | viewArray.append(view3) 44 | viewArray.append(view4) 45 | } 46 | 47 | let stackLayout = EEStackLayout(frame: CGRect(x: 0, y: 50, width: 200, height: 0), 48 | rowHeight: CGFloat(42), 49 | subviewHeight: CGFloat(20), 50 | spacingBetweenSubviews: CGFloat(15), 51 | leftPadding: CGFloat(15), 52 | rightPadding: CGFloat(15), 53 | subviews:viewArray) 54 | 55 | XCTAssertTrue(stackLayout.subviews.count == 7) 56 | } 57 | 58 | func test_single_line_stack_layout() { 59 | for _ in 1...1 { 60 | let view1 = UIView(frame: CGRect(x: 0, y: 0, width: 20, height: 42)) 61 | view1.backgroundColor = .green 62 | 63 | let view2 = UIView(frame: CGRect(x: 0, y: 0, width: 30, height: 42)) 64 | view2.backgroundColor = .blue 65 | 66 | let view3 = UIView(frame: CGRect(x: 0, y: 0, width: 40, height: 42)) 67 | view3.backgroundColor = .yellow 68 | 69 | let view4 = UIView(frame: CGRect(x: 0, y: 0, width: 50, height: 42)) 70 | view4.backgroundColor = .black 71 | 72 | viewArray.append(view1) 73 | viewArray.append(view2) 74 | viewArray.append(view3) 75 | viewArray.append(view4) 76 | } 77 | 78 | 79 | let stackLayout = EEStackLayout(frame: CGRect(x: 0, y: 50, width: 250, height: 0), 80 | rowHeight: CGFloat(42), 81 | subviewHeight: CGFloat(20), 82 | spacingBetweenSubviews: CGFloat(15), 83 | leftPadding: CGFloat(15), 84 | rightPadding: CGFloat(15), 85 | subviews:viewArray) 86 | 87 | XCTAssertTrue(stackLayout.subviews.count == 1) 88 | } 89 | 90 | } 91 | -------------------------------------------------------------------------------- /Tests/EEStackLayoutTests/XCTestManifests.swift: -------------------------------------------------------------------------------- 1 | import XCTest 2 | 3 | #if !canImport(ObjectiveC) 4 | public func allTests() -> [XCTestCaseEntry] { 5 | return [ 6 | testCase(EEStackLayoutTests.allTests), 7 | ] 8 | } 9 | #endif 10 | -------------------------------------------------------------------------------- /Tests/LinuxMain.swift: -------------------------------------------------------------------------------- 1 | import XCTest 2 | 3 | import EEStackLayoutTests 4 | 5 | var tests = [XCTestCaseEntry]() 6 | tests += EEStackLayoutTests.allTests() 7 | XCTMain(tests) 8 | -------------------------------------------------------------------------------- /example1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/efekanegeli/EEStackLayout/a2ba407ddf2ff53cdfdfd50d5087c1db218f0213/example1.png --------------------------------------------------------------------------------