Skip to content

Commit f19e812

Browse files
author
Baris Sencan
committed
Example code in README
1 parent 747eff5 commit f19e812

File tree

1 file changed

+56
-1
lines changed

1 file changed

+56
-1
lines changed

README.md

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,62 @@ 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: "",
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+
}
65+
66+
override func viewWillLayoutSubviews() {
67+
titleLabel.sizeToFit()
68+
titleLabel.top = 20
69+
titleLabel.centerX = view.centerX
70+
subtitleLabel.sizeToFit()
71+
subtitleLabel.top = titleLabel.bottom + 8
72+
subtitleLabel.centerX = view.centerX
73+
yinView.top = view.height / 2
74+
yinView.bottom2 = 0
75+
}
76+
77+
private func generateTextStyle(smaller: Bool = false) -> [NSObject: AnyObject] {
78+
return [
79+
NSFontAttributeName: UIFont.systemFontOfSize(smaller ? 14 : 16),
80+
NSForegroundColorAttributeName: UIColor.whiteColor()
81+
]
82+
}
83+
}
84+
```
3085

3186
#API Cheat Sheet
3287

0 commit comments

Comments
 (0)