Skip to content

Commit 42f552a

Browse files
committed
Resized images into documentation
1 parent 49ba56b commit 42f552a

File tree

1 file changed

+19
-27
lines changed

1 file changed

+19
-27
lines changed

README.md

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
[![Carthage Compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
77
[![Twitter](https://img.shields.io/badge/[email protected]?style=flat)](http://twitter.com/danielemargutti)
88

9-
109
SwiftRichString is a lightweight library which allows to create and manipulate attributed strings easily both in iOS, macOS, tvOS and even watchOS.
1110
It provides convenient way to store styles you can reuse in your app's UI elements, allows complex tag-based strings rendering and also includes integration with Interface Builder.
1211

@@ -61,14 +60,11 @@ self.label?.attributedText = str.set(style: myGroup)
6160

6261
That's the result!
6362

64-
<img src="Documentation_Assests/image_2.png" alt="" style="width: 70px;"/>
65-
66-
--
63+
<img src="Documentation_Assests/image_2.png" alt="" width=70px/>
6764

6865
## Documentation
6966

7067
- [Introduction to `Style`, `StyleGroup` & `StyleRegEx`](#stylestylegroup)
71-
- [Introduction](#introduction)
7268
- [String & Attributed String concatenation](#concatenation)
7369
- [Apply styles to `String` & `Attributed String`](#manualstyling)
7470
- [Fonts & Colors in `Style`](#fontscolors)
@@ -95,17 +91,13 @@ Other info:
9591

9692
## Introduction to `Style`, `StyleGroup`, `StyleRegEx`
9793

98-
<a name="introduction"/>
99-
100-
### Introduction
101-
10294
The main concept behind SwiftRichString is the use of `StyleProtocol` as generic container of the attributes you can apply to both `String` and `NSMutableAttributedString`.
10395
Concrete classes derivated by `StyleProtocol` are: `Style`, `StyleGroup` and `StyleRegEx`.
10496

10597
Each of these classes can be used as source for styles you can apply to a string, substring or attributed string.
10698

10799

108-
#### `Style`: apply style to strings or attributed strings
100+
### `Style`: apply style to strings or attributed strings
109101

110102
A `Style` is a class which encapsulate all the attributes you can apply to a string. The vast majority of the attributes of both AppKit/UIKit are currently available via type-safe properties by this class.
111103

@@ -121,7 +113,7 @@ let style = Style {
121113
let attrString = "Some text".set(style: style) // attributed string
122114
```
123115

124-
#### `StyleGroup`: Apply styles for tag-based complex string
116+
### `StyleGroup`: Apply styles for tag-based complex string
125117

126118
`Style` instances are anonymous; if you want to use a style instance to render a tag-based plain string you need to include it inside a `StyleGroup`. You can consider a `StyleGroup` as a container of `Styles` (but, in fact, thanks to the conformance to a common `StyleProtocol`'s protocol your group may contains other sub-groups too).
127119

@@ -140,7 +132,7 @@ The following code defines a group where:
140132
- we have defined two other styles named `h1` and `h2`; these styles are applied to the source string when parser encounter some text enclosed by these tags.
141133

142134

143-
#### `StyleRegEx`: Apply styles via regular expressions
135+
### `StyleRegEx`: Apply styles via regular expressions
144136

145137
`StyleRegEx` allows you to define a style which is applied when certain regular expression is matched inside the target string/attributed string.
146138

@@ -156,11 +148,11 @@ let attrString = "My email is [email protected] and my website is http:/
156148

157149
The result is this:
158150

159-
<img src="Documentation_Assests/image_4.png" alt="" style="width: 400px;"/>
151+
<img src="Documentation_Assests/image_4.png" alt="" width=400px/>
160152

161153
<a name="concatenation"/>
162154

163-
### String & Attributed String concatenation
155+
## String & Attributed String concatenation
164156
SwiftRichString allows you to simplify string concatenation by providing custom `+` operator between `String`,`AttributedString` (typealias of `NSMutableAttributedString`) and `Style`.
165157

166158
This a an example:
@@ -187,11 +179,11 @@ let attStr = "Hello" + ("\(username)" + big)
187179

188180
<a name="manualstyling"/>
189181

190-
### Apply styles to `String` & `Attributed String`
182+
## Apply styles to `String` & `Attributed String`
191183

192184
Both `String` and `Attributed String` (aka `NSMutableAttributedString`) has a come convenience methods you can use to create an manipulate attributed text easily via code:
193185

194-
#### Strings Instance Methods
186+
### Strings Instance Methods
195187

196188
- `set(style: String, range: NSRange? = nil)`: apply a globally registered style to the string (or a substring) by producing an attributed string.
197189
- `set(styles: [String], range: NSRange? = nil)`: apply an ordered sequence of globally registered styles to the string (or a substring) by producing an attributed string.
@@ -216,7 +208,7 @@ let a2: AttributedString = "Hello <h1>world</h1>, <h2>welcome here</h2>".set(sty
216208
let a3 = "Hello Guys!".set(Style({ $0.font = SystemFonts.Helvetica_Bold.font(size: 20) }), range: NSMakeRange(0,4))
217209
```
218210

219-
#### AttributedString Instance Methods
211+
### AttributedString Instance Methods
220212

221213
Similar methods are also available to attributed strings.
222214

@@ -297,7 +289,7 @@ Clearly you can still pass instances of both colors/fonts.
297289

298290
<a name="derivatingstyle"/>
299291

300-
### Derivating a `Style`
292+
## Derivating a `Style`
301293

302294
Sometimes you may need to infer properties of a new style from an existing one. In this case you can use `byAdding()` function of `Style` to produce a new style with all the properties of the receiver and the chance to configure additional/replacing attributes.
303295

@@ -335,7 +327,7 @@ let style = Style {
335327

336328
<a name="xmlstrings"/>
337329

338-
### Render XML tagged strings
330+
## Render XML/HTML tagged strings
339331

340332
SwiftRichString is also able to parse and render xml tagged strings to produce a valid `NSAttributedString` instance. This is particularly useful when you receive dynamic strings from remote services and you need to produce a rendered string easily.
341333

@@ -374,7 +366,7 @@ self.textView?.attributedText = bodyHTML.set(style: group)
374366

375367
<a name="customizexmlstrings"/>
376368

377-
### Customize XML rendering: react to tag's attributes and unknown tags
369+
## Customize XML rendering: react to tag's attributes and unknown tags
378370

379371
You can also add custom attributes to your tags and render it as you prefer: you need to provide a croncrete implementation of `XMLDynamicAttributesResolver` protocol and assign it to the `StyleGroup`'s `.xmlAttributesResolver` property.
380372

@@ -455,13 +447,13 @@ self.textView?.attributedText = sourceHTML.set(style: groupStyle)
455447

456448
The result is this:
457449

458-
<img src="Documentation_Assests/image_5.png" alt="" style="width: 300px;"/>
450+
<img src="Documentation_Assests/image_5.png" alt="" width=300px/>
459451

460452
where the `b` tag's blue color was overriden by the color tag attributes and the link in 'here' is clickable.
461453

462454
<a name="texttransforms"/>
463455

464-
### Custom Text Transforms
456+
## Custom Text Transforms
465457

466458
Sometimes you want to apply custom text transforms to your string; for example you may want to make some text with a given style uppercased with current locale.
467459
In order to provide custom text transform in `Style` instances just set one or more `TextTransform` to your `Style`'s `.textTransforms` property:
@@ -496,7 +488,7 @@ All text transforms are applied in the same ordered you set in `textTransform` p
496488

497489
<a name="images"/>
498490

499-
### Local & Remote Images inside text
491+
## Local & Remote Images inside text
500492

501493
SwiftRichString supports local and remote attached images along with attributed text.
502494
You can create an attributed string with an image with a single line:
@@ -529,15 +521,15 @@ self.textView?.attributedText = taggedText.set(style: ...)
529521

530522
This is the result:
531523

532-
<img src="Documentation_Assests/image_6.png" alt="" style="width: 100px;"/>
524+
<img src="Documentation_Assests/image_6.png" alt="" width=100px/>
533525

534526
<a name="stylemanager"/>
535527

536528
## The `StyleManager`
537529

538530
<a name="globalregister"/>
539531

540-
### Register globally available styles
532+
## Register globally available styles
541533
Styles can be created as you need or registered globally to be used once you need.
542534
This second approach is strongly suggested because allows you to theme your app as you need and also avoid duplication of the code.
543535

@@ -573,7 +565,7 @@ or you can assign `body` string to the `styledText` via Interface Builder design
573565

574566
<a name="defer"/>
575567

576-
### Defer style creation on demand
568+
## Defer style creation on demand
577569
Sometimes you may need to return a particular style used only in small portion of your app; while you can still set it directly you can also defer its creation in `StylesManager`.
578570

579571
By implementing `onDeferStyle()` callback you have an option to create a new style once required: you will receive the identifier of the style.
@@ -606,7 +598,7 @@ The following code return a valid style for `myStyle` identifier and cache it; i
606598

607599
Now you can use your style to render, for example, a tag based text into an `UILabel`: just set the name of the style to use.
608600

609-
<img src="Documentation_Assests/image_3.png" alt="" style="width: 400px;"/>
601+
<img src="Documentation_Assests/image_3.png" alt="" width=400px>
610602

611603
<a name="ib"/>
612604

0 commit comments

Comments
 (0)