├── .DS_Store ├── README.md ├── ScrollableStackView.xcodeproj ├── project.pbxproj └── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ └── IDEWorkspaceChecks.plist └── ScrollableStackView ├── AppDelegate.swift ├── Assets.xcassets ├── AppIcon.appiconset │ └── Contents.json └── Contents.json ├── Base.lproj ├── LaunchScreen.storyboard └── Main.storyboard ├── Info.plist └── ViewController.swift /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vasarhelyia/ScrollableStackview/2ef3d151e7b578e7ac0c10ad3ed0ad4cfb844ad7/.DS_Store -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ScrollableStackview 2 | 3 | An example app to demonstrate how to properly lay out `UIStackView`s embedded in `UIScrollView`s. 4 | 5 | Accompanying the [article about scrollable `UIStackView`s on `AlltheFlow blog`](https://blog.alltheflow.com/scrollable-uistackview/). 6 | -------------------------------------------------------------------------------- /ScrollableStackView.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 50; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 0295FF9D210E713600DC0697 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0295FF9C210E713600DC0697 /* AppDelegate.swift */; }; 11 | 0295FF9F210E713600DC0697 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0295FF9E210E713600DC0697 /* ViewController.swift */; }; 12 | 0295FFA2210E713600DC0697 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 0295FFA0210E713600DC0697 /* Main.storyboard */; }; 13 | 0295FFA4210E713A00DC0697 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 0295FFA3210E713A00DC0697 /* Assets.xcassets */; }; 14 | 0295FFA7210E713A00DC0697 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 0295FFA5210E713A00DC0697 /* LaunchScreen.storyboard */; }; 15 | /* End PBXBuildFile section */ 16 | 17 | /* Begin PBXFileReference section */ 18 | 0295FF99210E713600DC0697 /* ScrollableStackView.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ScrollableStackView.app; sourceTree = BUILT_PRODUCTS_DIR; }; 19 | 0295FF9C210E713600DC0697 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 20 | 0295FF9E210E713600DC0697 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 21 | 0295FFA1210E713600DC0697 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 22 | 0295FFA3210E713A00DC0697 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 23 | 0295FFA6210E713A00DC0697 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 24 | 0295FFA8210E713A00DC0697 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 25 | /* End PBXFileReference section */ 26 | 27 | /* Begin PBXFrameworksBuildPhase section */ 28 | 0295FF96210E713600DC0697 /* Frameworks */ = { 29 | isa = PBXFrameworksBuildPhase; 30 | buildActionMask = 2147483647; 31 | files = ( 32 | ); 33 | runOnlyForDeploymentPostprocessing = 0; 34 | }; 35 | /* End PBXFrameworksBuildPhase section */ 36 | 37 | /* Begin PBXGroup section */ 38 | 0295FF90210E713600DC0697 = { 39 | isa = PBXGroup; 40 | children = ( 41 | 0295FF9B210E713600DC0697 /* ScrollableStackView */, 42 | 0295FF9A210E713600DC0697 /* Products */, 43 | ); 44 | sourceTree = ""; 45 | }; 46 | 0295FF9A210E713600DC0697 /* Products */ = { 47 | isa = PBXGroup; 48 | children = ( 49 | 0295FF99210E713600DC0697 /* ScrollableStackView.app */, 50 | ); 51 | name = Products; 52 | sourceTree = ""; 53 | }; 54 | 0295FF9B210E713600DC0697 /* ScrollableStackView */ = { 55 | isa = PBXGroup; 56 | children = ( 57 | 0295FF9C210E713600DC0697 /* AppDelegate.swift */, 58 | 0295FF9E210E713600DC0697 /* ViewController.swift */, 59 | 0295FFA0210E713600DC0697 /* Main.storyboard */, 60 | 0295FFA3210E713A00DC0697 /* Assets.xcassets */, 61 | 0295FFA5210E713A00DC0697 /* LaunchScreen.storyboard */, 62 | 0295FFA8210E713A00DC0697 /* Info.plist */, 63 | ); 64 | path = ScrollableStackView; 65 | sourceTree = ""; 66 | }; 67 | /* End PBXGroup section */ 68 | 69 | /* Begin PBXNativeTarget section */ 70 | 0295FF98210E713600DC0697 /* ScrollableStackView */ = { 71 | isa = PBXNativeTarget; 72 | buildConfigurationList = 0295FFAB210E713A00DC0697 /* Build configuration list for PBXNativeTarget "ScrollableStackView" */; 73 | buildPhases = ( 74 | 0295FF95210E713600DC0697 /* Sources */, 75 | 0295FF96210E713600DC0697 /* Frameworks */, 76 | 0295FF97210E713600DC0697 /* Resources */, 77 | ); 78 | buildRules = ( 79 | ); 80 | dependencies = ( 81 | ); 82 | name = ScrollableStackView; 83 | productName = ScrollableStackView; 84 | productReference = 0295FF99210E713600DC0697 /* ScrollableStackView.app */; 85 | productType = "com.apple.product-type.application"; 86 | }; 87 | /* End PBXNativeTarget section */ 88 | 89 | /* Begin PBXProject section */ 90 | 0295FF91210E713600DC0697 /* Project object */ = { 91 | isa = PBXProject; 92 | attributes = { 93 | LastSwiftUpdateCheck = 0940; 94 | LastUpgradeCheck = 0940; 95 | ORGANIZATIONNAME = "Agnes Vasarhelyi"; 96 | TargetAttributes = { 97 | 0295FF98210E713600DC0697 = { 98 | CreatedOnToolsVersion = 9.4; 99 | }; 100 | }; 101 | }; 102 | buildConfigurationList = 0295FF94210E713600DC0697 /* Build configuration list for PBXProject "ScrollableStackView" */; 103 | compatibilityVersion = "Xcode 9.3"; 104 | developmentRegion = en; 105 | hasScannedForEncodings = 0; 106 | knownRegions = ( 107 | en, 108 | Base, 109 | ); 110 | mainGroup = 0295FF90210E713600DC0697; 111 | productRefGroup = 0295FF9A210E713600DC0697 /* Products */; 112 | projectDirPath = ""; 113 | projectRoot = ""; 114 | targets = ( 115 | 0295FF98210E713600DC0697 /* ScrollableStackView */, 116 | ); 117 | }; 118 | /* End PBXProject section */ 119 | 120 | /* Begin PBXResourcesBuildPhase section */ 121 | 0295FF97210E713600DC0697 /* Resources */ = { 122 | isa = PBXResourcesBuildPhase; 123 | buildActionMask = 2147483647; 124 | files = ( 125 | 0295FFA7210E713A00DC0697 /* LaunchScreen.storyboard in Resources */, 126 | 0295FFA4210E713A00DC0697 /* Assets.xcassets in Resources */, 127 | 0295FFA2210E713600DC0697 /* Main.storyboard in Resources */, 128 | ); 129 | runOnlyForDeploymentPostprocessing = 0; 130 | }; 131 | /* End PBXResourcesBuildPhase section */ 132 | 133 | /* Begin PBXSourcesBuildPhase section */ 134 | 0295FF95210E713600DC0697 /* Sources */ = { 135 | isa = PBXSourcesBuildPhase; 136 | buildActionMask = 2147483647; 137 | files = ( 138 | 0295FF9F210E713600DC0697 /* ViewController.swift in Sources */, 139 | 0295FF9D210E713600DC0697 /* AppDelegate.swift in Sources */, 140 | ); 141 | runOnlyForDeploymentPostprocessing = 0; 142 | }; 143 | /* End PBXSourcesBuildPhase section */ 144 | 145 | /* Begin PBXVariantGroup section */ 146 | 0295FFA0210E713600DC0697 /* Main.storyboard */ = { 147 | isa = PBXVariantGroup; 148 | children = ( 149 | 0295FFA1210E713600DC0697 /* Base */, 150 | ); 151 | name = Main.storyboard; 152 | sourceTree = ""; 153 | }; 154 | 0295FFA5210E713A00DC0697 /* LaunchScreen.storyboard */ = { 155 | isa = PBXVariantGroup; 156 | children = ( 157 | 0295FFA6210E713A00DC0697 /* Base */, 158 | ); 159 | name = LaunchScreen.storyboard; 160 | sourceTree = ""; 161 | }; 162 | /* End PBXVariantGroup section */ 163 | 164 | /* Begin XCBuildConfiguration section */ 165 | 0295FFA9210E713A00DC0697 /* Debug */ = { 166 | isa = XCBuildConfiguration; 167 | buildSettings = { 168 | ALWAYS_SEARCH_USER_PATHS = NO; 169 | CLANG_ANALYZER_NONNULL = YES; 170 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 171 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 172 | CLANG_CXX_LIBRARY = "libc++"; 173 | CLANG_ENABLE_MODULES = YES; 174 | CLANG_ENABLE_OBJC_ARC = YES; 175 | CLANG_ENABLE_OBJC_WEAK = YES; 176 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 177 | CLANG_WARN_BOOL_CONVERSION = YES; 178 | CLANG_WARN_COMMA = YES; 179 | CLANG_WARN_CONSTANT_CONVERSION = YES; 180 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 181 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 182 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 183 | CLANG_WARN_EMPTY_BODY = YES; 184 | CLANG_WARN_ENUM_CONVERSION = YES; 185 | CLANG_WARN_INFINITE_RECURSION = YES; 186 | CLANG_WARN_INT_CONVERSION = YES; 187 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 188 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 189 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 190 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 191 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 192 | CLANG_WARN_STRICT_PROTOTYPES = YES; 193 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 194 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 195 | CLANG_WARN_UNREACHABLE_CODE = YES; 196 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 197 | CODE_SIGN_IDENTITY = "iPhone Developer"; 198 | COPY_PHASE_STRIP = NO; 199 | DEBUG_INFORMATION_FORMAT = dwarf; 200 | ENABLE_STRICT_OBJC_MSGSEND = YES; 201 | ENABLE_TESTABILITY = YES; 202 | GCC_C_LANGUAGE_STANDARD = gnu11; 203 | GCC_DYNAMIC_NO_PIC = NO; 204 | GCC_NO_COMMON_BLOCKS = YES; 205 | GCC_OPTIMIZATION_LEVEL = 0; 206 | GCC_PREPROCESSOR_DEFINITIONS = ( 207 | "DEBUG=1", 208 | "$(inherited)", 209 | ); 210 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 211 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 212 | GCC_WARN_UNDECLARED_SELECTOR = YES; 213 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 214 | GCC_WARN_UNUSED_FUNCTION = YES; 215 | GCC_WARN_UNUSED_VARIABLE = YES; 216 | IPHONEOS_DEPLOYMENT_TARGET = 11.4; 217 | MTL_ENABLE_DEBUG_INFO = YES; 218 | ONLY_ACTIVE_ARCH = YES; 219 | SDKROOT = iphoneos; 220 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 221 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 222 | }; 223 | name = Debug; 224 | }; 225 | 0295FFAA210E713A00DC0697 /* Release */ = { 226 | isa = XCBuildConfiguration; 227 | buildSettings = { 228 | ALWAYS_SEARCH_USER_PATHS = NO; 229 | CLANG_ANALYZER_NONNULL = YES; 230 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 231 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 232 | CLANG_CXX_LIBRARY = "libc++"; 233 | CLANG_ENABLE_MODULES = YES; 234 | CLANG_ENABLE_OBJC_ARC = YES; 235 | CLANG_ENABLE_OBJC_WEAK = YES; 236 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 237 | CLANG_WARN_BOOL_CONVERSION = YES; 238 | CLANG_WARN_COMMA = YES; 239 | CLANG_WARN_CONSTANT_CONVERSION = YES; 240 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 241 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 242 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 243 | CLANG_WARN_EMPTY_BODY = YES; 244 | CLANG_WARN_ENUM_CONVERSION = YES; 245 | CLANG_WARN_INFINITE_RECURSION = YES; 246 | CLANG_WARN_INT_CONVERSION = YES; 247 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 248 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 249 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 250 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 251 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 252 | CLANG_WARN_STRICT_PROTOTYPES = YES; 253 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 254 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 255 | CLANG_WARN_UNREACHABLE_CODE = YES; 256 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 257 | CODE_SIGN_IDENTITY = "iPhone Developer"; 258 | COPY_PHASE_STRIP = NO; 259 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 260 | ENABLE_NS_ASSERTIONS = NO; 261 | ENABLE_STRICT_OBJC_MSGSEND = YES; 262 | GCC_C_LANGUAGE_STANDARD = gnu11; 263 | GCC_NO_COMMON_BLOCKS = YES; 264 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 265 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 266 | GCC_WARN_UNDECLARED_SELECTOR = YES; 267 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 268 | GCC_WARN_UNUSED_FUNCTION = YES; 269 | GCC_WARN_UNUSED_VARIABLE = YES; 270 | IPHONEOS_DEPLOYMENT_TARGET = 11.4; 271 | MTL_ENABLE_DEBUG_INFO = NO; 272 | SDKROOT = iphoneos; 273 | SWIFT_COMPILATION_MODE = wholemodule; 274 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 275 | VALIDATE_PRODUCT = YES; 276 | }; 277 | name = Release; 278 | }; 279 | 0295FFAC210E713A00DC0697 /* Debug */ = { 280 | isa = XCBuildConfiguration; 281 | buildSettings = { 282 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 283 | CODE_SIGN_STYLE = Automatic; 284 | DEVELOPMENT_TEAM = ""; 285 | INFOPLIST_FILE = ScrollableStackView/Info.plist; 286 | LD_RUNPATH_SEARCH_PATHS = ( 287 | "$(inherited)", 288 | "@executable_path/Frameworks", 289 | ); 290 | PRODUCT_BUNDLE_IDENTIFIER = com.vasarhelyia.ScrollableStackView; 291 | PRODUCT_NAME = "$(TARGET_NAME)"; 292 | SWIFT_VERSION = 4.0; 293 | TARGETED_DEVICE_FAMILY = "1,2"; 294 | }; 295 | name = Debug; 296 | }; 297 | 0295FFAD210E713A00DC0697 /* Release */ = { 298 | isa = XCBuildConfiguration; 299 | buildSettings = { 300 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 301 | CODE_SIGN_STYLE = Automatic; 302 | DEVELOPMENT_TEAM = ""; 303 | INFOPLIST_FILE = ScrollableStackView/Info.plist; 304 | LD_RUNPATH_SEARCH_PATHS = ( 305 | "$(inherited)", 306 | "@executable_path/Frameworks", 307 | ); 308 | PRODUCT_BUNDLE_IDENTIFIER = com.vasarhelyia.ScrollableStackView; 309 | PRODUCT_NAME = "$(TARGET_NAME)"; 310 | SWIFT_VERSION = 4.0; 311 | TARGETED_DEVICE_FAMILY = "1,2"; 312 | }; 313 | name = Release; 314 | }; 315 | /* End XCBuildConfiguration section */ 316 | 317 | /* Begin XCConfigurationList section */ 318 | 0295FF94210E713600DC0697 /* Build configuration list for PBXProject "ScrollableStackView" */ = { 319 | isa = XCConfigurationList; 320 | buildConfigurations = ( 321 | 0295FFA9210E713A00DC0697 /* Debug */, 322 | 0295FFAA210E713A00DC0697 /* Release */, 323 | ); 324 | defaultConfigurationIsVisible = 0; 325 | defaultConfigurationName = Release; 326 | }; 327 | 0295FFAB210E713A00DC0697 /* Build configuration list for PBXNativeTarget "ScrollableStackView" */ = { 328 | isa = XCConfigurationList; 329 | buildConfigurations = ( 330 | 0295FFAC210E713A00DC0697 /* Debug */, 331 | 0295FFAD210E713A00DC0697 /* Release */, 332 | ); 333 | defaultConfigurationIsVisible = 0; 334 | defaultConfigurationName = Release; 335 | }; 336 | /* End XCConfigurationList section */ 337 | }; 338 | rootObject = 0295FF91210E713600DC0697 /* Project object */; 339 | } 340 | -------------------------------------------------------------------------------- /ScrollableStackView.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /ScrollableStackView.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /ScrollableStackView/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // ScrollableStackView 4 | // 5 | // Created by Agnes Vasarhelyi on 7/29/18. 6 | // Copyright © 2018 Agnes Vasarhelyi. 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 | -------------------------------------------------------------------------------- /ScrollableStackView/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 | } -------------------------------------------------------------------------------- /ScrollableStackView/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /ScrollableStackView/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 | -------------------------------------------------------------------------------- /ScrollableStackView/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 | -------------------------------------------------------------------------------- /ScrollableStackView/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 | -------------------------------------------------------------------------------- /ScrollableStackView/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // ScrollableStackView 4 | // 5 | // Created by Agnes Vasarhelyi on 7/29/18. 6 | // Copyright © 2018 Agnes Vasarhelyi. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ViewController: UIViewController { 12 | 13 | override func viewDidLoad() { 14 | super.viewDidLoad() 15 | 16 | // Scroll view, vertical 17 | let scrollView = UIScrollView() 18 | self.view.addSubview(scrollView) 19 | 20 | scrollView.translatesAutoresizingMaskIntoConstraints = false 21 | NSLayoutConstraint.activate([ 22 | scrollView.leadingAnchor.constraint(equalTo: self.view.leadingAnchor), 23 | scrollView.trailingAnchor.constraint(equalTo: self.view.trailingAnchor), 24 | scrollView.topAnchor.constraint(equalTo: self.view.topAnchor), 25 | scrollView.bottomAnchor.constraint(equalTo: self.view.bottomAnchor) 26 | ]) 27 | 28 | // 1. The content is just a green view 29 | /* 30 | let greenView = UIView() 31 | greenView.backgroundColor = .green 32 | scrollView.addSubview(greenView) 33 | 34 | greenView.translatesAutoresizingMaskIntoConstraints = false 35 | NSLayoutConstraint.activate([ 36 | // Attaching the content's edges to the scroll view's edges 37 | greenView.leadingAnchor.constraint(equalTo: scrollView.leadingAnchor), 38 | greenView.trailingAnchor.constraint(equalTo: scrollView.trailingAnchor), 39 | greenView.topAnchor.constraint(equalTo: scrollView.topAnchor), 40 | greenView.bottomAnchor.constraint(equalTo: scrollView.bottomAnchor), 41 | 42 | // Satisfying size constraints 43 | greenView.widthAnchor.constraint(equalTo: scrollView.widthAnchor), 44 | greenView.heightAnchor.constraint(equalToConstant: 2000), 45 | ]) 46 | */ 47 | 48 | // 2. Content is a stack view 49 | let stackView = UIStackView() 50 | stackView.axis = .vertical 51 | stackView.alignment = .fill 52 | stackView.spacing = 0 53 | stackView.distribution = .fill 54 | scrollView.addSubview(stackView) 55 | 56 | stackView.translatesAutoresizingMaskIntoConstraints = false 57 | NSLayoutConstraint.activate([ 58 | // Attaching the content's edges to the scroll view's edges 59 | stackView.leadingAnchor.constraint(equalTo: scrollView.leadingAnchor), 60 | stackView.trailingAnchor.constraint(equalTo: scrollView.trailingAnchor), 61 | stackView.topAnchor.constraint(equalTo: scrollView.topAnchor), 62 | stackView.bottomAnchor.constraint(equalTo: scrollView.bottomAnchor), 63 | 64 | // Satisfying size constraints 65 | stackView.widthAnchor.constraint(equalTo: scrollView.widthAnchor) 66 | ]) 67 | 68 | // Add arranged subviews: 69 | for i in 0...20 { 70 | // A simple green view. 71 | let greenView = UIView() 72 | greenView.backgroundColor = .green 73 | stackView.addArrangedSubview(greenView) 74 | greenView.translatesAutoresizingMaskIntoConstraints = false 75 | // Doesn't have intrinsic content size, so we have to provide the height at least 76 | greenView.heightAnchor.constraint(equalToConstant: 100).isActive = true 77 | 78 | // Label (has instrinsic content size) 79 | let label = UILabel() 80 | label.backgroundColor = .orange 81 | label.text = "I'm label \(i)." 82 | label.textAlignment = .center 83 | stackView.addArrangedSubview(label) 84 | } 85 | } 86 | } 87 | 88 | 89 | --------------------------------------------------------------------------------