Skip to content

Commit 525299e

Browse files
author
Baris Sencan
committed
Merge branch 'master' into feature/proper-tests
2 parents fe841a2 + bfa1068 commit 525299e

File tree

1 file changed

+67
-1
lines changed

1 file changed

+67
-1
lines changed

README.md

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,63 @@ Not yet available.
2626

2727
#Usage
2828

29-
Coming soon.
29+
Just `import ManualLayout` in your code and use the methods and properties provided by the library to layout your views.
30+
31+
###A Simple Example
32+
33+
Here is the complete code for a basic view controller.
34+
35+
```swift
36+
import Foundation
37+
import ManualLayout
38+
39+
internal final class ExampleViewController: UIViewController {
40+
let titleLabel = UILabel(frame: CGRectZero)
41+
let subtitleLabel = UILabel(frame: CGRectZero)
42+
let yinView = UIView(frame: CGRectZero)
43+
44+
override init() {
45+
super.init(nibName: nil, bundle: nil)
46+
titleLabel.attributedText = NSAttributedString(
47+
string: "Hello World!",
48+
attributes: generateTextStyle())
49+
subtitleLabel.attributedText = NSAttributedString(
50+
string: "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
51+
attributes: generateTextStyle(smaller: true)
52+
yinView.backgroundColor = UIColor.blackColor()
53+
}
54+
55+
required override init(coder aDecoder: NSCoder) {
56+
fatalError("storyboards are incompatible with truth and beauty")
57+
}
58+
59+
override func viewDidLoad() {
60+
super.viewDidLoad()
61+
view.backgroundColor = UIColor.whiteColor()
62+
view.addSubview(titleLabel)
63+
view.addSubview(subtitleLabel)
64+
view.addSubview(yinView)
65+
}
66+
67+
override func viewWillLayoutSubviews() {
68+
titleLabel.sizeToFit()
69+
titleLabel.top = 20
70+
titleLabel.centerX = view.centerX
71+
subtitleLabel.sizeToFit()
72+
subtitleLabel.top = titleLabel.bottom + 8
73+
subtitleLabel.centerX = view.centerX
74+
yinView.top = view.height / 2
75+
yinView.bottom2 = view.height
76+
}
77+
78+
private func generateTextStyle(smaller: Bool = false) -> [NSObject: AnyObject] {
79+
return [
80+
NSFontAttributeName: UIFont.systemFontOfSize(smaller ? 14 : 16),
81+
NSForegroundColorAttributeName: UIColor.whiteColor()
82+
]
83+
}
84+
}
85+
```
3086

3187
#API Cheat Sheet
3288

@@ -50,8 +106,18 @@ var left: CGFloat
50106
var size: CGSize
51107
var width: CGFloat
52108
var height: CGFloat
109+
110+
// Alternate edges. Their names may change in the near future.
111+
var top2: CGFloat
112+
var right2: CGFloat
113+
var bottom2: CGFloat
114+
var left2: CGFloat
53115
```
54116

117+
The difference between alternate edges and normal edges require a bit of explaining. Imagine we have a view at position (0, 0) of size (100, 100) named *myView*. If we do `myView.right = 200`, then its position is now (200, 0) and its size remains unchaged. However, back when our view was located at (0, 0), if we had done `myView.right2 = 200`, then *myView* would have still been at (0, 0) but would have had a size of (200, 0).
118+
119+
So basically, *setting a normal edge's position drags the whole view along with that edge but setting an alternative edge's position drags just that edge*. And don't worry if you, for example, try to drag a left edge past its view's right edge. Edge swapping is done automatically so you don't have to worry about.
120+
55121
###CALayer/UIView Methods
56122

57123
Replace the word "layer" with "view" for the UIView methods.

0 commit comments

Comments
 (0)