Skip to content

Commit 25bb69c

Browse files
author
Mike Amaral
committedOct 6, 2015
Added example to README for grouping relative to sibling view.
1 parent 93195ef commit 25bb69c

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed
 

Diff for: ‎Demo/TestViewController.swift

+10-6
Original file line numberDiff line numberDiff line change
@@ -60,45 +60,49 @@ class TestViewController: UIViewController {
6060
view1.textAlignment = .Center
6161
view1.font = UIFont.boldSystemFontOfSize(20)
6262
view1.textColor = UIColor.whiteColor()
63-
anchorViewA.addSubview(view1)
63+
view.addSubview(view1)
6464

6565
view2.backgroundColor = UIColor(red: 132/255.0, green: 169/255.0, blue: 57/255.0, alpha: 1.0)
6666
view2.text = "2"
6767
view2.textAlignment = .Center
6868
view2.font = UIFont.boldSystemFontOfSize(20)
6969
view2.textColor = UIColor.whiteColor()
70-
anchorViewA.addSubview(view2)
70+
view.addSubview(view2)
7171

7272
view3.backgroundColor = UIColor(red: 78/255.0, green: 102/255.0, blue: 131/255.0, alpha: 1.0)
7373
view3.text = "3"
7474
view3.textAlignment = .Center
7575
view3.font = UIFont.boldSystemFontOfSize(20)
7676
view3.textColor = UIColor.whiteColor()
77-
anchorViewA.addSubview(view3)
77+
view.addSubview(view3)
7878

7979
view4.backgroundColor = UIColor(red: 132/255.0, green: 169/255.0, blue: 57/255.0, alpha: 1.0)
8080
view4.text = "4"
8181
view4.textAlignment = .Center
8282
view4.font = UIFont.boldSystemFontOfSize(20)
8383
view4.textColor = UIColor.whiteColor()
84-
anchorViewB.addSubview(view4)
84+
view.addSubview(view4)
8585

8686
view5.backgroundColor = UIColor(red: 78/255.0, green: 102/255.0, blue: 131/255.0, alpha: 1.0)
8787
view5.text = "5"
8888
view5.textAlignment = .Center
8989
view5.font = UIFont.boldSystemFontOfSize(20)
9090
view5.textColor = UIColor.whiteColor()
91-
anchorViewB.addSubview(view5)
91+
view.addSubview(view5)
9292

9393
view6.backgroundColor = UIColor(red: 132/255.0, green: 169/255.0, blue: 57/255.0, alpha: 1.0)
9494
view6.text = "6"
9595
view6.textAlignment = .Center
9696
view6.font = UIFont.boldSystemFontOfSize(20)
9797
view6.textColor = UIColor.whiteColor()
98-
anchorViewB.addSubview(view6)
98+
view.addSubview(view6)
9999
}
100100

101101
override func viewWillLayoutSubviews() {
102102
super.viewWillLayoutSubviews()
103+
104+
anchorViewA.anchorInCenter(width: 200, height: 200)
105+
view.groupAndAlign(group: .Horizontal, andAlign: .ToTheRightMatchingTop, views: [view1, view2, view3], relativeTo: anchorViewA, padding: 10, width: 50, height: 50)
106+
view.groupAndAlign(group: .Vertical, andAlign: .UnderCentered, views: [view4, view5, view6], relativeTo: anchorViewA, padding: 10, width: 50, height: 50)
103107
}
104108
}

Diff for: ‎README.md

+9
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,15 @@ anchorViewB.groupAgainstEdge(group: .Vertical, views: [view4, view5, view6], aga
204204

205205
![Group against edge](Screenshots/group_against_edge.png)
206206

207+
Grouping views relative to a sibling view can be done as well:
208+
209+
```swift
210+
view.groupAndAlign(group: .Horizontal, andAlign: .ToTheRightMatchingTop, views: [view1, view2, view3], relativeTo: anchorViewA, padding: padding, width: size, height: size)
211+
view.groupAndAlign(group: .Vertical, andAlign: .UnderCentered, views: [view4, view5, view6], relativeTo: anchorViewA, padding: padding, width: size, height: size)
212+
```
213+
214+
![Group relative](Screenshots/group_relative.png)
215+
207216
You can also specify that you want a group of subviews to fill their superview, either horizontally or vertically:
208217

209218
```swift

0 commit comments

Comments
 (0)