You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+8-11Lines changed: 8 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,22 +18,21 @@ Documentation is automatically generated from source code comments and rendered
18
18
Usage
19
19
----------
20
20
21
-
## 1. UIView extensions for declarative Auto Layout
21
+
###1. UIView extensions for declarative Auto Layout
22
22
23
23
To aid in auto layout, Y—CoreUI has several `UIView` extensions that simplify creating layout constraints. These do not use any 3rd party library such as SnapKit, but are simply wrappers around Apple’s own `NSLayoutConstraint` api’s. If you are more comfortable using Apple’s layout constraint api’s natively, then by all means go ahead and use them. But these convenience methods allow for less verbose code that expresses its intent more directly.
24
24
25
25
All the extensions are to `UIView` and begin with the word `constrain`.
26
26
27
27
The simplest flavor just creates constraints using attributes just like the original iOS 6 `NSLayoutContraint` api.
28
28
29
-
30
29
```swift
31
-
//constrain a button's width to 100
30
+
//constrain a button's width to 100
32
31
let button =UIButton()
33
32
addSubview(button)
34
33
button.constrain(.width, constant: 100)
35
34
36
-
//constrain view to superview**
35
+
//constrain view to superview
37
36
38
37
let container =UIView()
39
38
addSubview(container)
@@ -46,7 +45,7 @@ container.constrain(.bottom, to: .bottom, of: superview)
46
45
Another flavor creates constraints using anchors just like the anchor api’s first introduced in iOS 9.
47
46
48
47
```swift
49
-
//constrain a button's width to 100
48
+
//constrain a button's width to 100
50
49
let button =UIButton()
51
50
addSubview(button)
52
51
button.constrain(.widthAnchor, constant: 100)
@@ -113,7 +112,7 @@ addSubview(container)
113
112
container.constrainEdgesToMargins()
114
113
```
115
114
116
-
## 2. UIColor extensions for WCAG 2.0 contrast ratio calculations
115
+
###2. UIColor extensions for WCAG 2.0 contrast ratio calculations
117
116
118
117
Y—CoreUI contains a number of extensions to make working with colors easier. The most useful of them may be WCAG 2.0 contrast calculations. Given any two colors (representing foreground and background colors), you can calculate the contrast ration between them and evaluate whether that passes particular WCAG 2.0 standards (AA or AAA). You can even write unit tests to quickly check all color pairs in your app across all color modes. That could look like this:
119
118
@@ -188,24 +187,22 @@ final class ColorsTests: XCTestCase {
188
187
}
189
188
```
190
189
191
-
## 3. UIScrollView extensions to assist with keyboard avoidance
190
+
###3. UIScrollView extensions to assist with keyboard avoidance
192
191
193
-
`FormViewController` is a view controller with a scrollable content area that will automatically avoid the keyboard for you. It is a good choice for views that have inputs (e.g. login or onboarding). Even for views without inputs, it is still quite useful for managing the creation of a `UIScrollView` and a `contentView` set within it, so that you can focus on your content and not have to code a scrollView for every view.
192
+
#### `FormViewController` is a view controller with a scrollable content area that will automatically avoid the keyboard for you. It is a good choice for views that have inputs (e.g. login or onboarding). Even for views without inputs, it is still quite useful for managing the creation of a `UIScrollView` and a `contentView` set within it, so that you can focus on your content and not have to code a scrollView for every view.
194
193
195
194
<aside>
196
195
💡 Almost every full-screen view in your app that contains any text should be a scroll view because of the vagaries of localization, Dynamic Type, potentially small screen sizes, and landscape mode support.
197
-
198
196
</aside>
199
197
200
-
## `UIScrollview` Extensions
198
+
####`UIScrollview` Extensions
201
199
202
200
Want to have a scrollview that avoids the keyboard, but you can’t use `FormViewController`? Most of its functionality is a simple extension to `UIScrollView`. You can add keyboard avoidance to any scroll view like so:
0 commit comments