-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updates to StackViewSynthesis2 and LearnAboutAutoLayout
- Loading branch information
Eric Hyche
committed
Aug 6, 2017
1 parent
5610590
commit 3622476
Showing
28 changed files
with
427 additions
and
345 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
LearnAboutAutoLayout.playground/Pages/Ambiguous Layouts.xcplaygroundpage/Contents.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import UIKit | ||
import PlaygroundSupport | ||
|
||
// This is our sample container view which allows us | ||
// to adjust the width and height of the container | ||
let liveView = EHAdjustableContainerView(frame: CGRect(x: 0.0, y: 0.0, width: 512.0, height: 512.0)) | ||
|
||
let label = UILabel(frame: .zero) | ||
label.translatesAutoresizingMaskIntoConstraints = false | ||
label.backgroundColor = .purple | ||
label.text = "111" | ||
label.textColor = .white | ||
label.font = UIFont.systemFont(ofSize: 32.0) | ||
|
||
liveView.containerView.addSubview(label) | ||
|
||
// Let's center the label vertically. | ||
let centerY = NSLayoutConstraint(item: label, attribute: .centerY, relatedBy: .equal, | ||
toItem: liveView.containerView, attribute: .centerY, multiplier: 1.0, constant: 0.0) | ||
liveView.containerView.addConstraint(centerY) | ||
|
||
// But we won't specify a horizontal position constraint. | ||
// Where does the view wind up? | ||
|
||
//let isLabelAmbiguous = label.hasAmbiguousLayout | ||
//let isContainerAmbiguous = liveView.containerView.hasAmbiguousLayout | ||
|
||
|
||
PlaygroundPage.current.needsIndefiniteExecution = true | ||
PlaygroundPage.current.liveView = liveView | ||
|
16 changes: 16 additions & 0 deletions
16
LearnAboutAutoLayout.playground/Pages/Ambiguous Layouts.xcplaygroundpage/timeline.xctimeline
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Timeline | ||
version = "3.0"> | ||
<TimelineItems> | ||
<LoggerValueHistoryTimelineItem | ||
documentLocation = "#CharacterRangeLen=24&CharacterRangeLoc=905&EndingColumnNumber=25&EndingLineNumber=24&StartingColumnNumber=1&StartingLineNumber=24&Timestamp=523680276.124883" | ||
selectedRepresentationIndex = "0" | ||
shouldTrackSuperviewWidth = "NO"> | ||
</LoggerValueHistoryTimelineItem> | ||
<LoggerValueHistoryTimelineItem | ||
documentLocation = "#CharacterRangeLen=41&CharacterRangeLoc=959&EndingColumnNumber=42&EndingLineNumber=25&StartingColumnNumber=1&StartingLineNumber=25&Timestamp=523680276.125081" | ||
selectedRepresentationIndex = "0" | ||
shouldTrackSuperviewWidth = "NO"> | ||
</LoggerValueHistoryTimelineItem> | ||
</TimelineItems> | ||
</Timeline> |
54 changes: 54 additions & 0 deletions
54
...nAboutAutoLayout.playground/Pages/Constraint Inequalities.xcplaygroundpage/Contents.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import UIKit | ||
import PlaygroundSupport | ||
|
||
// This is our sample container view which allows us | ||
// to adjust the width and height of the container | ||
let liveView = EHAdjustableContainerView(frame: CGRect(x: 0.0, y: 0.0, width: 512.0, height: 512.0)) | ||
|
||
let image = UIImageView(image: UIImage(named: "steve-large.jpg")) | ||
image.translatesAutoresizingMaskIntoConstraints = false | ||
|
||
liveView.containerView.addSubview(image) | ||
|
||
// Center the image vertically | ||
let centerY = NSLayoutConstraint(item: image, attribute: .centerY, relatedBy: .equal, | ||
toItem: liveView.containerView, attribute: .centerY, multiplier: 1.0, constant: 0.0) | ||
centerY.priority = UILayoutPriorityRequired | ||
// Center the image horizontally | ||
let centerX = NSLayoutConstraint(item: image, attribute: .centerX, relatedBy: .equal, | ||
toItem: liveView.containerView, attribute: .centerX, multiplier: 1.0, constant: 0.0) | ||
centerX.priority = UILayoutPriorityRequired | ||
|
||
// Make the height of the image equal to the width | ||
let aspect1 = NSLayoutConstraint(item: image, attribute: .height, relatedBy: .equal, | ||
toItem: image, attribute: .width, multiplier: 1.0, constant: 0.0) | ||
aspect1.priority = UILayoutPriorityRequired | ||
|
||
// Make the image width half of the container width | ||
let imageHalf = NSLayoutConstraint(item: image, attribute: .width, relatedBy: .equal, | ||
toItem: liveView.containerView, attribute: .width, multiplier: 0.5, constant: 0.0) | ||
imageHalf.priority = UILayoutPriorityRequired | ||
|
||
// Put a minimum width of 40 | ||
let minWidth = NSLayoutConstraint(item: image, attribute: .width, relatedBy: .greaterThanOrEqual, | ||
toItem: nil, attribute: .notAnAttribute, multiplier: 1.0, constant: 100.0) | ||
minWidth.priority = UILayoutPriorityRequired | ||
|
||
// Put a maximum width of 80 | ||
let maxWidth = NSLayoutConstraint(item: image, attribute: .width, relatedBy: .lessThanOrEqual, | ||
toItem: nil, attribute: .notAnAttribute, multiplier: 1.0, constant: 200.0) | ||
maxWidth.priority = UILayoutPriorityRequired | ||
|
||
// Then you need to add the constraints to the appropriate view. | ||
// You add it to the most immediate common ancestor of both views involved in the constraint. | ||
liveView.containerView.addConstraint(centerY) | ||
liveView.containerView.addConstraint(centerX) | ||
liveView.containerView.addConstraint(imageHalf) | ||
image.addConstraint(aspect1) | ||
image.addConstraint(minWidth) | ||
image.addConstraint(maxWidth) | ||
|
||
|
||
PlaygroundPage.current.needsIndefiniteExecution = true | ||
PlaygroundPage.current.liveView = liveView | ||
|
6 changes: 6 additions & 0 deletions
6
...tAutoLayout.playground/Pages/Constraint Inequalities.xcplaygroundpage/timeline.xctimeline
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Timeline | ||
version = "3.0"> | ||
<TimelineItems> | ||
</TimelineItems> | ||
</Timeline> |
60 changes: 60 additions & 0 deletions
60
...nAboutAutoLayout.playground/Pages/Hugging and Compression.xcplaygroundpage/Contents.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import UIKit | ||
import PlaygroundSupport | ||
|
||
// This is our sample container view which allows us | ||
// to adjust the width and height of the container | ||
let liveView = EHAdjustableContainerView(frame: CGRect(x: 0.0, y: 0.0, width: 512.0, height: 512.0)) | ||
|
||
let label0 = UILabel(frame: .zero) | ||
label0.translatesAutoresizingMaskIntoConstraints = false | ||
label0.backgroundColor = .purple | ||
label0.text = "CH=750,CR=250" | ||
label0.textColor = .white | ||
label0.font = UIFont.systemFont(ofSize: 24.0) | ||
label0.setContentHuggingPriority(UILayoutPriorityDefaultHigh, for: .horizontal) | ||
label0.setContentCompressionResistancePriority(UILayoutPriorityDefaultLow, for: .horizontal) | ||
|
||
liveView.containerView.addSubview(label0) | ||
|
||
let label1 = UILabel(frame: .zero) | ||
label1.translatesAutoresizingMaskIntoConstraints = false | ||
label1.backgroundColor = .brown | ||
label1.text = "CH=250,CR=750" | ||
label1.textColor = .white | ||
label1.font = UIFont.systemFont(ofSize: 24.0) | ||
label1.setContentHuggingPriority(UILayoutPriorityDefaultLow, for: .horizontal) | ||
label1.setContentCompressionResistancePriority(UILayoutPriorityDefaultHigh, for: .horizontal) | ||
|
||
liveView.containerView.addSubview(label0) | ||
liveView.containerView.addSubview(label1) | ||
|
||
// Assign the vertical center of the label to the vertical center of the container | ||
let centerY0 = NSLayoutConstraint(item: label0, attribute: .centerY, relatedBy: .equal, | ||
toItem: liveView.containerView, attribute: .centerY, multiplier: 1.0, constant: 0.0) | ||
let centerY1 = NSLayoutConstraint(item: label1, attribute: .centerY, relatedBy: .equal, | ||
toItem: liveView.containerView, attribute: .centerY, multiplier: 1.0, constant: 0.0) | ||
|
||
// Position the label0 20 points to the right of the left edge of the container | ||
let label0leading = NSLayoutConstraint(item: label0, attribute: .leading, relatedBy: .equal, | ||
toItem: liveView.containerView, attribute: .leading, multiplier: 1.0, constant: 20.0) | ||
|
||
// Position the label1 right edge 20 points from the right edge of the container | ||
let label1trailing = NSLayoutConstraint(item: liveView.containerView, attribute: .trailing, relatedBy: .equal, | ||
toItem: label1, attribute: .trailing, multiplier: 1.0, constant: 20.0) | ||
|
||
// Put some space between the labels | ||
let label0label1gap = NSLayoutConstraint(item: label1, attribute: .leading, relatedBy: .equal, | ||
toItem: label0, attribute: .trailing, multiplier: 1.0, constant: 20.0) | ||
|
||
// Then you need to add the constraints to the appropriate view. | ||
// You add it to the most immediate common ancestor of both views involved in the constraint. | ||
liveView.containerView.addConstraint(centerY0) | ||
liveView.containerView.addConstraint(centerY1) | ||
liveView.containerView.addConstraint(label0leading) | ||
liveView.containerView.addConstraint(label1trailing) | ||
liveView.containerView.addConstraint(label0label1gap) | ||
|
||
|
||
PlaygroundPage.current.needsIndefiniteExecution = true | ||
PlaygroundPage.current.liveView = liveView | ||
|
6 changes: 6 additions & 0 deletions
6
...tAutoLayout.playground/Pages/Hugging and Compression.xcplaygroundpage/timeline.xctimeline
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Timeline | ||
version = "3.0"> | ||
<TimelineItems> | ||
</TimelineItems> | ||
</Timeline> |
53 changes: 29 additions & 24 deletions
53
...nAboutAutoLayout.playground/Pages/Introducing Constraints.xcplaygroundpage/Contents.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
LearnAboutAutoLayout.playground/Pages/Unsatisfiable Layouts.xcplaygroundpage/Contents.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import UIKit | ||
import PlaygroundSupport | ||
|
||
// This is our sample container view which allows us | ||
// to adjust the width and height of the container | ||
let liveView = EHAdjustableContainerView(frame: CGRect(x: 0.0, y: 0.0, width: 512.0, height: 512.0)) | ||
|
||
let label = UILabel(frame: .zero) | ||
label.translatesAutoresizingMaskIntoConstraints = false | ||
label.backgroundColor = .purple | ||
label.text = "111" | ||
label.textColor = .white | ||
label.font = UIFont.systemFont(ofSize: 32.0) | ||
|
||
liveView.containerView.addSubview(label) | ||
|
||
// Assign the vertical center of the label to the vertical center of the container | ||
let centerY = NSLayoutConstraint(item: label, attribute: .centerY, relatedBy: .equal, | ||
toItem: liveView.containerView, attribute: .centerY, multiplier: 1.0, constant: 0.0) | ||
// Position the label 20 points to the left of the left edge of the container | ||
let leading = NSLayoutConstraint(item: label, attribute: .leading, relatedBy: .equal, | ||
toItem: liveView.containerView, attribute: .leading, multiplier: 1.0, constant: 20.0) | ||
// Now also add a conflicting constraint putting the | ||
// center of the label 40 points below the top. | ||
let top = NSLayoutConstraint(item: label, attribute: .centerY, relatedBy: .equal, | ||
toItem: liveView.containerView, attribute: .top, multiplier: 1.0, constant: 40.0) | ||
|
||
// Then you need to add the constraints to the appropriate view. | ||
// You add it to the most immediate common ancestor of both views involved in the constraint. | ||
liveView.containerView.addConstraint(centerY) | ||
liveView.containerView.addConstraint(leading) | ||
liveView.containerView.addConstraint(top) | ||
|
||
|
||
PlaygroundPage.current.needsIndefiniteExecution = true | ||
PlaygroundPage.current.liveView = liveView | ||
|
6 changes: 6 additions & 0 deletions
6
...outAutoLayout.playground/Pages/Unsatisfiable Layouts.xcplaygroundpage/timeline.xctimeline
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Timeline | ||
version = "3.0"> | ||
<TimelineItems> | ||
</TimelineItems> | ||
</Timeline> |
7 changes: 0 additions & 7 deletions
7
LearnAboutAutoLayout.playground/Pages/Untitled Page 2.xcplaygroundpage/Contents.swift
This file was deleted.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+2.4 KB
(110%)
...round/playground.xcworkspace/xcuserdata/ehyche.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
...codeproj/project.xcworkspace/xcuserdata/ehyche.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown.
Binary file modified
BIN
+4.04 KB
(200%)
...codeproj/project.xcworkspace/xcuserdata/ehyche.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+1.51 KB
(110%)
...codeproj/project.xcworkspace/xcuserdata/ehyche.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
StackViewSynthesis2/StackViewSynthesis2/Assets.xcassets/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"info" : { | ||
"version" : 1, | ||
"author" : "xcode" | ||
} | ||
} |
Oops, something went wrong.