Skip to content

Commit 04f4226

Browse files
committed
Reformatting
1 parent 7aeaf78 commit 04f4226

File tree

1 file changed

+96
-78
lines changed

1 file changed

+96
-78
lines changed

README.md

+96-78
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# RichString
2+
23
*The easiest way to work with attributed strings in Swift*
34

45
![Swift Version 4](https://img.shields.io/badge/Swift-v4-yellow.svg)
@@ -9,16 +10,16 @@
910
[![license](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/svdo/swift-RichString/blob/master/LICENSE)
1011
[![Build Status](https://travis-ci.org/svdo/swift-RichString.svg?branch=master)](https://travis-ci.org/svdo/swift-RichString)
1112

12-
1313
## Introduction
14-
This Swift framework was built to simplify working with `NSAttributedString`. It does
15-
so without adding additional types; it just extends the existing types that you already have,
16-
ensuring that it is fully interoperable with any other method of using `NSAttributedString`.
1714

18-
The core assumption this framework makes, is that you
19-
set up your attributed strings by first configuring
20-
all components appropriately, and then concatenating
21-
them.
15+
This Swift framework was built to simplify working with `NSAttributedString`. It
16+
does so without adding additional types; it just extends the existing types that
17+
you already have, ensuring that it is fully interoperable with any other method
18+
of using `NSAttributedString`.
19+
20+
The core assumption this framework makes, is that you set up your attributed
21+
strings by first configuring all components appropriately, and then
22+
concatenating them.
2223

2324
It allows you to do things like this:
2425

@@ -31,13 +32,13 @@ let content = title + text
3132
```
3233

3334
## Overview
34-
This framework provides the following primitives.
35-
There are unit tests; have a look at them for more
36-
examples.
35+
36+
This framework provides the following primitives. There are unit tests; have a
37+
look at them for more examples.
3738

3839
### Operator `+` For Concatenating Attributed Strings
39-
Given two strings, you can append one to the other
40-
using the `+` operator:
40+
41+
Given two strings, you can append one to the other using the `+` operator:
4142

4243
```swift
4344
let s1 = NSAttributedString()
@@ -48,37 +49,41 @@ let concatenated = s1 + s2
4849
### `RichString` protocol for `String`, `NSString` and `NSAttributedString`
4950

5051
#### font(_:)
51-
Apply the given font. The type `Font` is a type
52-
alias of `UIFont` on iOS, and of `NSFont` on macOS.
52+
53+
Apply the given font. The type `Font` is a type alias of `UIFont` on iOS, and of
54+
`NSFont` on macOS.
5355

5456
```swift
5557
let attributedString = "text".font(.systemFont(ofSize: 12))
5658
```
59+
5760
#### fontSize(_:)
58-
Applies the given font size. If no font was set on
59-
the attributed string yet, `Font.systemFont` will be
60-
assumed.
6161

62-
Note: unlike on iOS, on macOS this returns an
63-
*optional* attributed string instead.
62+
Applies the given font size. If no font was set on the attributed string yet,
63+
`Font.systemFont` will be assumed.
64+
65+
Note: unlike on iOS, on macOS this returns an *optional* attributed string
66+
instead.
6467

6568
```swift
6669
let attributedString = "text".fontSize(12)
6770
```
6871

6972
#### paragraphStyle(configure:)
70-
Applies a paragraph style, configuring it with the
71-
given closure. If the attributed string already had
72-
a paragraph style attribute, the `configure` closure
73-
is called on that paragraph style; otherwise a new
73+
74+
Applies a paragraph style, configuring it with the given closure. If the
75+
attributed string already had a paragraph style attribute, the `configure`
76+
closure is called on that paragraph style; otherwise a new
7477
`NSMutableParagraphStyle` is used.
78+
7579
```swift
7680
let attributedString = "Hello World".paragraphStyle {
7781
$0.firstLineHeadIndent = 10
7882
}
7983
```
8084

8185
#### paragraphStyle(_:)
86+
8287
Applies the given paragraph style.
8388

8489
```swift
@@ -88,99 +93,102 @@ let attributedString = "text".paragraphStyle(paragraphStyle)
8893
```
8994

9095
#### color(_:)
96+
9197
Applies the given (foreground) color.
9298

9399
```swift
94100
let attributedString = "text".color(.blue)
95101
```
96102

97103
#### backgroundColor(_:)
104+
98105
Applies the given background color.
99106

100107
```swift
101108
let attributedString = "text".backgroundColor(.yellow)
102109
```
103110

104111
#### ligature(_:)
105-
Configures whether or not to use ligatures. Default
106-
is that they are used.
112+
113+
Configures whether or not to use ligatures. Default is that they are used.
107114

108115
```swift
109116
let attributedString = "text".ligature(false)
110117
```
111118

112119
#### kern(_:)
113-
Configures the amount with which to modify the
114-
default kerning. The default `0` means that no
115-
kerning change is applied.
120+
121+
Configures the amount with which to modify the default kerning. The default `0`
122+
means that no kerning change is applied.
116123

117124
```swift
118125
let attributedString = "text".kern(0.1)
119126
```
120127

121128
#### strikeThrough(style:)
122-
Configures the strike through style.
123129

124-
Please note that depending on OS and version not all
125-
styles may actually work.
130+
Configures the strike through style. Please note that depending on OS and
131+
version not all styles may actually work.
126132

127133
```swift
128134
let attributedString = "text".strikeThrough(style: .styleSingle)
129135
```
130136

131137
#### strikeThrough(color:)
132-
Configures the strike through color.
133-
Only setting the color has no effect, the style must
134-
be configured as well.
138+
139+
Configures the strike through color. Only setting the color has no effect, the
140+
style must be configured as well.
135141

136142
```swift
137143
let attributedString = "text".strikeThrough(color: .red)
138144
```
139145

140146
#### strikeThrough(color:, style:)
141-
Configures both the strike through color and style.
142-
Please note that depending on OS and version not all
143-
styles may actually work.
147+
148+
Configures both the strike through color and style. Please note that depending
149+
on OS and version not all styles may actually work.
144150

145151
```swift
146152
let attributedString = "text".strikeThrough(color: .red, style: .styleDouble)
147153
```
148154

149155
#### underline(style:)
150-
Configures the underline style.
151-
Please note that depending on OS and version not all
152-
styles may actually work.
156+
157+
Configures the underline style. Please note that depending on OS and version not
158+
all styles may actually work.
153159

154160
```swift
155161
let attributedString = "text".underline(style: .styleSingle)
156162
```
157163

158164
#### underline(color:)
159-
Configures the underline color.
160-
Only setting the color has no effect, the style must
161-
be configured as well.
165+
166+
Configures the underline color. Only setting the color has no effect, the style
167+
must be configured as well.
162168

163169
```swift
164170
let attributedString = "text".underline(color: .blue)
165171
```
166172

167173
#### underline(color:, style:)
168-
Configures both the underline color and style.
169-
Please note that depending on OS and version not all
170-
styles may actually work.
174+
175+
Configures both the underline color and style. Please note that depending on OS
176+
and version not all styles may actually work.
171177

172178
```swift
173179
let attributedString = "text".underline(color: .blue, style: .styleSingle)
174180
```
175181

176182
#### stroke(width:, color:)
183+
177184
Configures the stroke.
178185

179186
```swift
180187
let attributedString = "text".stroke(width: 2, color: .green)
181188
```
182189

183190
#### shadow(configure:)
191+
184192
Configures the shadow using a closure that receives
185193
an `NSShadow` instance. Not available on watchOS.
186194

@@ -193,8 +201,9 @@ let result = "Hello World".shadow {
193201
```
194202

195203
#### shadow(_:)
196-
Configures the shadow by setting an `NSShadow`
197-
instance. Not available on watchOS.
204+
205+
Configures the shadow by setting an `NSShadow` instance. Not available on
206+
watchOS.
198207

199208
```swift
200209
let shadow = NSShadow()
@@ -205,33 +214,35 @@ let attributedString = "text".shadow(shadow)
205214
```
206215

207216
#### letterPressed()
217+
208218
Adds the "letter pressed" text effect.
209219

210220
```swift
211221
let attributedString = "text".letterPressed()
212222
```
213223

214224
#### link(url:)
215-
Creates hyperlink to the given URL with the receiver
216-
as text.
225+
226+
Creates hyperlink to the given URL with the receiver as text.
217227

218228
```swift
219229
let url = URL(string: "https://example.com")
220230
let attributedString = "text".link(url: url)
221231
```
222232

223233
#### link(string:)
224-
Creates hyperlink to the given URL with the receiver
225-
as text.
234+
235+
Creates hyperlink to the given URL with the receiver as text.
226236

227237
```swift
228238
let urlString = "https://example.com"
229239
let attributedString = "text".link(string: urlString)
230240
```
231241

232242
#### attachment(configure:)
233-
Creates a new `NSTextAttachment` and passes it to the
234-
`configure` closure. Not available on watchOS.
243+
244+
Creates a new `NSTextAttachment` and passes it to the `configure` closure. Not
245+
available on watchOS.
235246

236247
```swift
237248
let attributedString = NSAttributedString().attachment {
@@ -241,20 +252,23 @@ let attributedString = NSAttributedString().attachment {
241252
```
242253

243254
#### baselineOffset(_:)
255+
244256
Configures the baseline offset.
245257

246258
```swift
247259
let attributedString = "text".baselineOffset(-0.5)
248260
```
249261

250262
#### obliqueness(_:)
263+
251264
Configures the skew to be applied to glyphs.
252265

253266
```swift
254267
let attributedString = "text".obliqueness(1.5)
255268
```
256269

257270
#### expansion(_:)
271+
258272
Configures the expansion to be applied to glyphs.
259273

260274
```swift
@@ -263,13 +277,12 @@ let attributedString = "text".expansion(2)
263277

264278
### `NSAttributedString` Extension for Getting Attribute Values
265279

266-
All of the above methods have corresponding getters
267-
to retrieve the attribute values from the attributed
268-
string. The all return an optional; if the attribute
269-
is not configured on the attributed string, `nil`
270-
will be returned.
280+
All of the above methods have corresponding getters to retrieve the attribute
281+
values from the attributed string. The all return an optional; if the attribute
282+
is not configured on the attributed string, `nil` will be returned.
271283

272284
The getters are:
285+
273286
- `attachment: NSTextAttachment?` (not available on watchOS)
274287
- `backgroundColor: Color?`
275288
- `baselineOffset: Float?`
@@ -291,23 +304,28 @@ The getters are:
291304
- `underlineStyle: NSUnderlineStyle?`
292305

293306
## Usage
294-
You can use the library any way you like, but two
295-
easy ways are Carthage and CocoaPods. For CocoaPods,
296-
put `pod RichString` in your `Podfile`.
307+
308+
You can use the library any way you like, but two easy ways are Carthage and
309+
CocoaPods. For CocoaPods, put `pod RichString` in your `Podfile`.
297310

298311
## Alternative Frameworks
299-
I found a couple other frameworks that have the same goal as this one: simplifying using
300-
`NSAttributedString`. I like mine better, mostly because it has a simpler API that doesn't
301-
use any additional types. But I'll let you choose for yourself.
302-
303-
[TextAttributes](https://github.com/delba/TextAttributes) is similar to this framework, but it
304-
introduces a new type that you have to set up the attributes, instead of working directly on
305-
the strings themselves. It doesn't feature the cool closure-based way of setting up
306-
`shadow { ... }` and `paragraphStyle { ... }` that this framework has. And it doesn't provide
307-
the super-convenient `+` operator that this framework does. Finally, I didn't test this framework
308-
on tvOS and watchOS. I'm rather confident that those will work as well, but you'll have to try.
309-
Pull requests are wellcome of course.
310-
311-
[TextAttributesUtil](https://github.com/muukii/TextAttributesUtil) also introduces a new type
312-
for setting up the attributes. Also, it's API forces you to have more levels of nesting in your
313-
source code. It only supports iOS, not macOS.
312+
313+
Back when I started, I found a couple other frameworks that have the same goal
314+
as this one: simplifying using `NSAttributedString`. I like mine better, mostly
315+
because it has a simpler API that doesn't use any additional types. But I'll let
316+
you choose for yourself. I haven't researched this anymore after that, so this
317+
is probably outdated.
318+
319+
[TextAttributes](https://github.com/delba/TextAttributes) is similar to this
320+
framework, but it introduces a new type that you have to set up the attributes,
321+
instead of working directly on the strings themselves. It doesn't feature the
322+
cool closure-based way of setting up `shadow { ... }` and `paragraphStyle { ...
323+
}` that this framework has. And it doesn't provide the super-convenient `+`
324+
operator that this framework does. Finally, I didn't test this framework on tvOS
325+
and watchOS. I'm rather confident that those will work as well, but you'll have
326+
to try. Pull requests are wellcome of course.
327+
328+
[TextAttributesUtil](https://github.com/muukii/TextAttributesUtil) also
329+
introduces a new type for setting up the attributes. Also, it's API forces you
330+
to have more levels of nesting in your source code. It only supports iOS, not
331+
macOS.

0 commit comments

Comments
 (0)