From 69114b7c823e53896474229a088e2e537d18021c Mon Sep 17 00:00:00 2001 From: Frederic Barthelemy Date: Wed, 25 Nov 2015 12:27:33 -0800 Subject: [PATCH 1/9] Fix Xcodeproj so iOS deployment target is inherited from the project settings, & update the deployment target to the lowest supported by the code. --- TZStackView.xcodeproj/project.pbxproj | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/TZStackView.xcodeproj/project.pbxproj b/TZStackView.xcodeproj/project.pbxproj index b9e35a1..d8cc958 100644 --- a/TZStackView.xcodeproj/project.pbxproj +++ b/TZStackView.xcodeproj/project.pbxproj @@ -16,10 +16,10 @@ A45441C21B9B6D71002452BA /* TZStackView.h in Headers */ = {isa = PBXBuildFile; fileRef = A45441C11B9B6D71002452BA /* TZStackView.h */; settings = {ATTRIBUTES = (Public, ); }; }; A45441C61B9B6D71002452BA /* TZStackView.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A45441BF1B9B6D71002452BA /* TZStackView.framework */; }; A45441C71B9B6D71002452BA /* TZStackView.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = A45441BF1B9B6D71002452BA /* TZStackView.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - A45441D01B9B6D9C002452BA /* TZSpacerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A45441CC1B9B6D9C002452BA /* TZSpacerView.swift */; settings = {ASSET_TAGS = (); }; }; - A45441D11B9B6D9C002452BA /* TZStackView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A45441CD1B9B6D9C002452BA /* TZStackView.swift */; settings = {ASSET_TAGS = (); }; }; - A45441D21B9B6D9C002452BA /* TZStackViewAlignment.swift in Sources */ = {isa = PBXBuildFile; fileRef = A45441CE1B9B6D9C002452BA /* TZStackViewAlignment.swift */; settings = {ASSET_TAGS = (); }; }; - A45441D31B9B6D9C002452BA /* TZStackViewDistribution.swift in Sources */ = {isa = PBXBuildFile; fileRef = A45441CF1B9B6D9C002452BA /* TZStackViewDistribution.swift */; settings = {ASSET_TAGS = (); }; }; + A45441D01B9B6D9C002452BA /* TZSpacerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A45441CC1B9B6D9C002452BA /* TZSpacerView.swift */; }; + A45441D11B9B6D9C002452BA /* TZStackView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A45441CD1B9B6D9C002452BA /* TZStackView.swift */; }; + A45441D21B9B6D9C002452BA /* TZStackViewAlignment.swift in Sources */ = {isa = PBXBuildFile; fileRef = A45441CE1B9B6D9C002452BA /* TZStackViewAlignment.swift */; }; + A45441D31B9B6D9C002452BA /* TZStackViewDistribution.swift in Sources */ = {isa = PBXBuildFile; fileRef = A45441CF1B9B6D9C002452BA /* TZStackViewDistribution.swift */; }; DB41AF6A1B294B8E003DB902 /* NSLayoutConstraintExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB41AF691B294B8E003DB902 /* NSLayoutConstraintExtension.swift */; }; DB5B70851B2A1963006043BD /* TestView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB5B70841B2A1963006043BD /* TestView.swift */; }; DB5B70871B2B8816006043BD /* TZStackViewTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB5B70861B2B8816006043BD /* TZStackViewTestCase.swift */; }; @@ -404,7 +404,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -442,7 +442,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; VALIDATE_PRODUCT = YES; @@ -517,7 +517,6 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = TZStackView/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = nl.tomvanzummeren.TZStackView; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -540,7 +539,6 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = TZStackView/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = nl.tomvanzummeren.TZStackView; PRODUCT_NAME = "$(TARGET_NAME)"; From 0e7dc8226c4de2854838350528b2f4bfd95857ed Mon Sep 17 00:00:00 2001 From: Frederic Barthelemy Date: Wed, 25 Nov 2015 12:32:53 -0800 Subject: [PATCH 2/9] Update README to be consistent with code-requirement of iOS 8.x or later. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c604c20..855dc5a 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ A wonderful layout component called the [`UIStackView` was introduced with *iOS `UIStackView` requires *iOS 9*, but we're not ready to make our apps require *iOS 9+* just yet. In the meanwhile, we developers are eager to try this component in our apps right now! This is why I created this replica of the `UIStackView`, called the `TZStackView` (TZ = Tom van Zummeren, my initials). I created this component very carefully, tested every single corner case and matched the results against the *real* `UIStackView` with automated `XCTestCases`. ## Features -- ✅ Compatible with **iOS 7.x** and **iOS 8.x** +- ✅ Compatible with **iOS 8.x** or later - ✅ Supports the complete API of `UIStackView` including **all** *distribution* and *alignment* options - ✅ Supports animating the `hidden` property of the *arranged subviews* - ❌ Supports *Storyboard* From c6b5f3b307770c775608a171a73960a7fa7ff6c0 Mon Sep 17 00:00:00 2001 From: Frederic Barthelemy Date: Wed, 25 Nov 2015 12:36:14 -0800 Subject: [PATCH 3/9] Set XcodeProj flag to indicate that TZStackView is written with space indenting. --- TZStackView.xcodeproj/project.pbxproj | 1 + 1 file changed, 1 insertion(+) diff --git a/TZStackView.xcodeproj/project.pbxproj b/TZStackView.xcodeproj/project.pbxproj index d8cc958..5036245 100644 --- a/TZStackView.xcodeproj/project.pbxproj +++ b/TZStackView.xcodeproj/project.pbxproj @@ -123,6 +123,7 @@ 5F50EB61965EE1FD3F76FB91 /* Products */, ); sourceTree = ""; + usesTabs = 0; }; 5F50E7526ADB7151E0540D2D /* TZStackViewTests */ = { isa = PBXGroup; From 13801f493628e5e86ff8a4c1b75afcae84e2b1b1 Mon Sep 17 00:00:00 2001 From: Frederic Barthelemy Date: Wed, 25 Nov 2015 12:37:46 -0800 Subject: [PATCH 4/9] Update TZStackViewAlignment to match UIStackViewAlignment from Apple. -- The enum values were in the wrong order, some were concrete values rather than aliases. --- TZStackView/TZStackView.swift | 12 ++++++---- TZStackView/TZStackViewAlignment.swift | 33 ++++++++++++++++++++++---- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/TZStackView/TZStackView.swift b/TZStackView/TZStackView.swift index 2fd77a8..e80c45d 100755 --- a/TZStackView/TZStackView.swift +++ b/TZStackView/TZStackView.swift @@ -476,12 +476,14 @@ public class TZStackView: UIView { constraints += equalAttributes(views: views, attribute: .Top) case .Center: constraints += equalAttributes(views: views, attribute: .CenterY) - case .Leading, .Top: + case .Leading: constraints += equalAttributes(views: views, attribute: .Top) - case .Trailing, .Bottom: + case .Trailing: constraints += equalAttributes(views: views, attribute: .Bottom) case .FirstBaseline: constraints += equalAttributes(views: views, attribute: .FirstBaseline) + case .LastBaseline: + constraints += equalAttributes(views: views, attribute: .LastBaseline) } case .Vertical: @@ -491,12 +493,14 @@ public class TZStackView: UIView { constraints += equalAttributes(views: views, attribute: .Trailing) case .Center: constraints += equalAttributes(views: views, attribute: .CenterX) - case .Leading, .Top: + case .Leading: constraints += equalAttributes(views: views, attribute: .Leading) - case .Trailing, .Bottom: + case .Trailing: constraints += equalAttributes(views: views, attribute: .Trailing) case .FirstBaseline: constraints += [] + case .LastBaseline: + constraints += [] } } return constraints diff --git a/TZStackView/TZStackViewAlignment.swift b/TZStackView/TZStackViewAlignment.swift index f99594f..5f1fc4b 100644 --- a/TZStackView/TZStackViewAlignment.swift +++ b/TZStackView/TZStackViewAlignment.swift @@ -9,11 +9,36 @@ import Foundation @objc public enum TZStackViewAlignment: Int { + /* Align the leading and trailing edges of vertically stacked items + or the top and bottom edges of horizontally stacked items tightly to the container. + */ case Fill - case Center + + /* Align the leading edges of vertically stacked items + or the top edges of horizontally stacked items tightly to the relevant edge + of the container + */ case Leading - case Top + public static var Top: TZStackViewAlignment { + get { + return .Leading + } + } + case FirstBaseline // Valid for horizontal axis only + + /* Center the items in a vertical stack horizontally + or the items in a horizontal stack vertically + */ + case Center + + /* Align the trailing edges of vertically stacked items + or the bottom edges of horizontally stacked items tightly to the relevant + edge of the container + */ case Trailing - case Bottom - case FirstBaseline + public static var Bottom: TZStackViewAlignment { get { + return .Trailing + } + } + case LastBaseline // Valid for horizontal axis only } From ae2b180daec2eeee3047a7aa60f582754d416aaf Mon Sep 17 00:00:00 2001 From: Frederic Barthelemy Date: Wed, 25 Nov 2015 12:38:55 -0800 Subject: [PATCH 5/9] Since other code already uses iOS 8.x-only features, switch from direct adding of NSLayoutConstraints to NSLayoutConstraint.activateConstraints. --- TZStackView/TZStackView.swift | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/TZStackView/TZStackView.swift b/TZStackView/TZStackView.swift index e80c45d..33a6c31 100755 --- a/TZStackView/TZStackView.swift +++ b/TZStackView/TZStackView.swift @@ -188,7 +188,6 @@ public class TZStackView: UIView { guideConstraint = constraint(item: arrangedSubview, attribute: .Width, toItem: nil, attribute: .NotAnAttribute, constant: 0, priority: 25) } subviewConstraints.append(guideConstraint) - arrangedSubview.addConstraint(guideConstraint) } if isHidden(arrangedSubview) { @@ -200,7 +199,6 @@ public class TZStackView: UIView { hiddenConstraint = constraint(item: arrangedSubview, attribute: .Height, toItem: nil, attribute: .NotAnAttribute, constant: 0) } subviewConstraints.append(hiddenConstraint) - arrangedSubview.addConstraint(hiddenConstraint) } } @@ -323,9 +321,10 @@ public class TZStackView: UIView { stackViewConstraints.append(constraint(item: self, attribute: .TopMargin, toItem: spacerViews[0])) } } - addConstraints(stackViewConstraints) } - + + NSLayoutConstraint.activateConstraints(subviewConstraints + stackViewConstraints) + super.updateConstraints() } From 6024a81a1e8a44b8a513652d3db855eca3e5224f Mon Sep 17 00:00:00 2001 From: Andreas Goese Date: Fri, 27 Nov 2015 19:03:27 +0100 Subject: [PATCH 6/9] Re-enabled iOS 7 support --- README.md | 2 +- TZStackView.xcodeproj/project.pbxproj | 6 +- TZStackView/TZStackView.swift | 128 ++++++++++++++++---------- 3 files changed, 83 insertions(+), 53 deletions(-) diff --git a/README.md b/README.md index 855dc5a..63393f8 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ A wonderful layout component called the [`UIStackView` was introduced with *iOS `UIStackView` requires *iOS 9*, but we're not ready to make our apps require *iOS 9+* just yet. In the meanwhile, we developers are eager to try this component in our apps right now! This is why I created this replica of the `UIStackView`, called the `TZStackView` (TZ = Tom van Zummeren, my initials). I created this component very carefully, tested every single corner case and matched the results against the *real* `UIStackView` with automated `XCTestCases`. ## Features -- ✅ Compatible with **iOS 8.x** or later +- ✅ Compatible with **iOS 7.x** or later - ✅ Supports the complete API of `UIStackView` including **all** *distribution* and *alignment* options - ✅ Supports animating the `hidden` property of the *arranged subviews* - ❌ Supports *Storyboard* diff --git a/TZStackView.xcodeproj/project.pbxproj b/TZStackView.xcodeproj/project.pbxproj index 5036245..b9e831c 100644 --- a/TZStackView.xcodeproj/project.pbxproj +++ b/TZStackView.xcodeproj/project.pbxproj @@ -405,7 +405,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 7.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -443,7 +443,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 7.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; VALIDATE_PRODUCT = YES; @@ -456,6 +456,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; EMBEDDED_CONTENT_CONTAINS_SWIFT = YES; INFOPLIST_FILE = TZStackViewDemo/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "nl.tomvanzummeren.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -500,6 +501,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; EMBEDDED_CONTENT_CONTAINS_SWIFT = YES; INFOPLIST_FILE = TZStackViewDemo/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "nl.tomvanzummeren.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; diff --git a/TZStackView/TZStackView.swift b/TZStackView/TZStackView.swift index 33a6c31..13eb730 100755 --- a/TZStackView/TZStackView.swift +++ b/TZStackView/TZStackView.swift @@ -220,8 +220,10 @@ public class TZStackView: UIView { stackViewConstraints += createMatchEdgesContraints(arrangedSubviews) stackViewConstraints += createFirstAndLastViewMatchEdgesContraints() - if alignment == .FirstBaseline && axis == .Horizontal { - stackViewConstraints.append(constraint(item: self, attribute: .Height, toItem: nil, attribute: .NotAnAttribute, priority: 49)) + if #available(iOS 8, *) { + if alignment == .FirstBaseline && axis == .Horizontal { + stackViewConstraints.append(constraint(item: self, attribute: .Height, toItem: nil, attribute: .NotAnAttribute, priority: 49)) + } } if distribution == .FillEqually { @@ -255,8 +257,10 @@ public class TZStackView: UIView { switch axis { case .Horizontal: stackViewConstraints.append(constraint(item: self, attribute: .Width, toItem: nil, attribute: .NotAnAttribute, priority: 49)) - if alignment == .FirstBaseline { - stackViewConstraints.append(constraint(item: self, attribute: .Height, toItem: nil, attribute: .NotAnAttribute, priority: 49)) + if #available(iOS 8, *) { + if alignment == .FirstBaseline { + stackViewConstraints.append(constraint(item: self, attribute: .Height, toItem: nil, attribute: .NotAnAttribute, priority: 49)) + } } case .Vertical: stackViewConstraints.append(constraint(item: self, attribute: .Height, toItem: nil, attribute: .NotAnAttribute, priority: 49)) @@ -281,8 +285,10 @@ public class TZStackView: UIView { switch axis { case .Horizontal: stackViewConstraints.append(constraint(item: self, attribute: .Width, toItem: nil, attribute: .NotAnAttribute, priority: 49)) - if alignment == .FirstBaseline { - stackViewConstraints.append(constraint(item: self, attribute: .Height, toItem: nil, attribute: .NotAnAttribute, priority: 49)) + if #available(iOS 8, *) { + if alignment == .FirstBaseline { + stackViewConstraints.append(constraint(item: self, attribute: .Height, toItem: nil, attribute: .NotAnAttribute, priority: 49)) + } } case .Vertical: stackViewConstraints.append(constraint(item: self, attribute: .Height, toItem: nil, attribute: .NotAnAttribute, priority: 49)) @@ -313,17 +319,24 @@ public class TZStackView: UIView { stackViewConstraints += createSurroundingSpacerViewConstraints(spacerViews[0], views: visibleArrangedSubviews) } - if layoutMarginsRelativeArrangement { - if spacerViews.count > 0 { - stackViewConstraints.append(constraint(item: self, attribute: .BottomMargin, toItem: spacerViews[0])) - stackViewConstraints.append(constraint(item: self, attribute: .LeftMargin, toItem: spacerViews[0])) - stackViewConstraints.append(constraint(item: self, attribute: .RightMargin, toItem: spacerViews[0])) - stackViewConstraints.append(constraint(item: self, attribute: .TopMargin, toItem: spacerViews[0])) + if #available(iOS 8, *) { + if layoutMarginsRelativeArrangement { + if spacerViews.count > 0 { + stackViewConstraints.append(constraint(item: self, attribute: .BottomMargin, toItem: spacerViews[0])) + stackViewConstraints.append(constraint(item: self, attribute: .LeftMargin, toItem: spacerViews[0])) + stackViewConstraints.append(constraint(item: self, attribute: .RightMargin, toItem: spacerViews[0])) + stackViewConstraints.append(constraint(item: self, attribute: .TopMargin, toItem: spacerViews[0])) + } } } } - NSLayoutConstraint.activateConstraints(subviewConstraints + stackViewConstraints) + let constraintsToActivate = subviewConstraints + stackViewConstraints + if #available(iOS 8.0, *) { + NSLayoutConstraint.activateConstraints(constraintsToActivate) + } else { + addConstraints(constraintsToActivate) + } super.updateConstraints() } @@ -467,41 +480,50 @@ public class TZStackView: UIView { private func createMatchEdgesContraints(views: [UIView]) -> [NSLayoutConstraint] { var constraints = [NSLayoutConstraint]() - switch axis { - case .Horizontal: - switch alignment { - case .Fill: - constraints += equalAttributes(views: views, attribute: .Bottom) - constraints += equalAttributes(views: views, attribute: .Top) - case .Center: - constraints += equalAttributes(views: views, attribute: .CenterY) - case .Leading: - constraints += equalAttributes(views: views, attribute: .Top) - case .Trailing: - constraints += equalAttributes(views: views, attribute: .Bottom) - case .FirstBaseline: - constraints += equalAttributes(views: views, attribute: .FirstBaseline) - case .LastBaseline: + switch (alignment, axis) { + case (.Fill, .Horizontal): // Fill alignment + constraints += equalAttributes(views: views, attribute: .Bottom) + constraints += equalAttributes(views: views, attribute: .Top) + case (.Fill, .Vertical): + constraints += equalAttributes(views: views, attribute: .Leading) + constraints += equalAttributes(views: views, attribute: .Trailing) + + case (.Center, .Horizontal): // Center alignment + constraints += equalAttributes(views: views, attribute: .CenterY) + case (.Center, .Vertical): + constraints += equalAttributes(views: views, attribute: .CenterX) + + case (.Leading, .Horizontal): // Leading & Top alignment + constraints += equalAttributes(views: views, attribute: .Top) + case (.Leading, .Vertical): + constraints += equalAttributes(views: views, attribute: .Leading) + + case (.Trailing, .Horizontal): // Trailing and Bottom alignment + constraints += equalAttributes(views: views, attribute: .Bottom) + case (.Trailing, .Vertical): + constraints += equalAttributes(views: views, attribute: .Trailing) + + case (.LastBaseline, .Horizontal): // Last-Baseline alignment, works only on horizontal axis + if #available(iOS 8, *) { constraints += equalAttributes(views: views, attribute: .LastBaseline) + } else { + constraints += equalAttributes(views: views, attribute: .Baseline) } - - case .Vertical: - switch alignment { - case .Fill: - constraints += equalAttributes(views: views, attribute: .Leading) - constraints += equalAttributes(views: views, attribute: .Trailing) - case .Center: - constraints += equalAttributes(views: views, attribute: .CenterX) - case .Leading: - constraints += equalAttributes(views: views, attribute: .Leading) - case .Trailing: - constraints += equalAttributes(views: views, attribute: .Trailing) - case .FirstBaseline: - constraints += [] - case .LastBaseline: + case (.LastBaseline, .Vertical): + constraints += [] + default: break + } + + if #available(iOS 8, *) { // First-Baseline alignment requires iOS 8+ + switch (alignment, axis) { + case (.FirstBaseline, .Horizontal): // First-Baseline alignment, works only on horizontal axis + constraints += equalAttributes(views: views, attribute: .FirstBaseline) + case (.FirstBaseline, .Vertical): constraints += [] + default: break } } + return constraints } @@ -515,21 +537,27 @@ public class TZStackView: UIView { var topView = arrangedSubviews.first! var bottomView = arrangedSubviews.first! + if spacerViews.count > 0 { - if alignment == .Center { + switch (alignment, axis) { + case (.Center, _): topView = spacerViews[0] bottomView = spacerViews[0] - } else if alignment == .Top || alignment == .Leading { + case (.Leading, _): bottomView = spacerViews[0] - } else if alignment == .Bottom || alignment == .Trailing { + case (.Trailing, _): topView = spacerViews[0] - } else if alignment == .FirstBaseline { - switch axis { - case .Horizontal: + default: break + } + + if #available(iOS 8, *) { + switch (alignment, axis) { + case (.FirstBaseline, .Horizontal): bottomView = spacerViews[0] - case .Vertical: + case (.FirstBaseline, .Vertical): topView = spacerViews[0] bottomView = spacerViews[0] + default: break } } } From a2fea4bad141f43fd37e4df6c2f1821b36ab4d81 Mon Sep 17 00:00:00 2001 From: Andreas Goese Date: Fri, 27 Nov 2015 19:22:16 +0100 Subject: [PATCH 7/9] Added ability to test LastBaseline in demo app --- TZStackViewDemo/ViewController.swift | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/TZStackViewDemo/ViewController.swift b/TZStackViewDemo/ViewController.swift index 482cd17..2a1475a 100644 --- a/TZStackViewDemo/ViewController.swift +++ b/TZStackViewDemo/ViewController.swift @@ -62,7 +62,7 @@ class ViewController: UIViewController { axisSegmentedControl.setContentCompressionResistancePriority(900, forAxis: .Horizontal) axisSegmentedControl.tintColor = UIColor.lightGrayColor() - alignmentSegmentedControl = UISegmentedControl(items: ["Fill", "Center", "Leading", "Top", "Trailing", "Bottom", "FirstBaseline"]) + alignmentSegmentedControl = UISegmentedControl(items: ["Fill", "Center", "Leading", "Top", "Trailing", "Bottom", "FirstBaseline", "LastBaseline"]) alignmentSegmentedControl.selectedSegmentIndex = 0 alignmentSegmentedControl.addTarget(self, action: "alignmentChanged:", forControlEvents: .ValueChanged) alignmentSegmentedControl.setContentCompressionResistancePriority(1000, forAxis: .Horizontal) @@ -156,8 +156,10 @@ class ViewController: UIViewController { tzStackView.alignment = .Trailing case 5: tzStackView.alignment = .Bottom - default: + case 6: tzStackView.alignment = .FirstBaseline + default: + tzStackView.alignment = .LastBaseline } tzStackView.setNeedsUpdateConstraints() } From ed16b27870ca4601f1a4042d5b97209a36fbdfa0 Mon Sep 17 00:00:00 2001 From: Andreas Goese Date: Fri, 27 Nov 2015 19:22:55 +0100 Subject: [PATCH 8/9] Fixed LastBaseline alignment --- TZStackView/TZStackView.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/TZStackView/TZStackView.swift b/TZStackView/TZStackView.swift index 13eb730..ac85855 100755 --- a/TZStackView/TZStackView.swift +++ b/TZStackView/TZStackView.swift @@ -547,6 +547,8 @@ public class TZStackView: UIView { bottomView = spacerViews[0] case (.Trailing, _): topView = spacerViews[0] + case (.LastBaseline, .Horizontal): + bottomView = spacerViews[0] default: break } From 210918e676655edc93becc345dfc7ae6da959298 Mon Sep 17 00:00:00 2001 From: Andreas Goese Date: Fri, 27 Nov 2015 19:23:42 +0100 Subject: [PATCH 9/9] FirstBaseline only supported for horizontal axis --- TZStackView/TZStackView.swift | 3 --- 1 file changed, 3 deletions(-) diff --git a/TZStackView/TZStackView.swift b/TZStackView/TZStackView.swift index ac85855..0bea05b 100755 --- a/TZStackView/TZStackView.swift +++ b/TZStackView/TZStackView.swift @@ -556,9 +556,6 @@ public class TZStackView: UIView { switch (alignment, axis) { case (.FirstBaseline, .Horizontal): bottomView = spacerViews[0] - case (.FirstBaseline, .Vertical): - topView = spacerViews[0] - bottomView = spacerViews[0] default: break } }