Skip to content

Commit a24bdce

Browse files
committed
Merge branch 'release/3.5.0'
2 parents d87ed23 + dde841e commit a24bdce

31 files changed

+1671
-587
lines changed

.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Documentation_Assests/Logo.sketch

8.08 KB
Binary file not shown.

Documentation_Assests/image_5.png

28.6 KB
Loading

Documentation_Assests/image_6.png

879 KB
Loading
2.27 KB
Loading
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "universal",
5+
"scale" : "1x"
6+
},
7+
{
8+
"idiom" : "universal",
9+
"filename" : "816c77975b4ccce940d41933081b19d7.png",
10+
"scale" : "2x"
11+
},
12+
{
13+
"idiom" : "universal",
14+
"scale" : "3x"
15+
}
16+
],
17+
"info" : {
18+
"version" : 1,
19+
"author" : "xcode"
20+
}
21+
}

ExampleiOS/Info.plist

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020
<string>1</string>
2121
<key>LSRequiresIPhoneOS</key>
2222
<true/>
23+
<key>NSAppTransportSecurity</key>
24+
<dict>
25+
<key>NSAllowsArbitraryLoads</key>
26+
<true/>
27+
</dict>
2328
<key>UILaunchStoryboardName</key>
2429
<string>LaunchScreen</string>
2530
<key>UIMainStoryboardFile</key>

ExampleiOS/UIKit+Extensions.swift

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//
2+
// UIKit+Extensions.swift
3+
// ExampleiOS
4+
//
5+
// Created by daniele on 21/12/2019.
6+
// Copyright © 2019 SwiftRichString. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
extension UIColor {
12+
13+
public static func randomColors(_ count: Int) -> [UIColor] {
14+
return (0..<count).map { _ -> UIColor in
15+
randomColor()
16+
}
17+
}
18+
19+
public static func randomColor() -> UIColor {
20+
let redValue = CGFloat.random(in: 0...1)
21+
let greenValue = CGFloat.random(in: 0...1)
22+
let blueValue = CGFloat.random(in: 0...1)
23+
24+
let randomColor = UIColor(red: redValue, green: greenValue, blue: blueValue, alpha: 1.0)
25+
return randomColor
26+
}
27+
28+
}
29+
30+
extension UIFont {
31+
32+
/// Return the same font with given weight.
33+
///
34+
/// - Parameter weight: weight you want to get
35+
public func withWeight(_ weight: UIFont.Weight) -> UIFont {
36+
let descriptor = fontDescriptor.addingAttributes([UIFontDescriptor.AttributeName.traits: [UIFontDescriptor.TraitKey.weight: weight]])
37+
return UIFont(descriptor: descriptor, size: 0) // size 0 means keep the size as it is
38+
}
39+
40+
}

ExampleiOS/ViewController.swift

Lines changed: 49 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,17 @@ class ViewController: UIViewController {
1616

1717
override func viewDidLoad() {
1818
super.viewDidLoad()
19-
20-
/*let baseStyle = Style {
21-
$0.font = UIFont.systemFont(ofSize: self.baseFontSize)
22-
$0.lineSpacing = 2
23-
}
24-
25-
let linkStyle = Style {
26-
$0.font = UIFont.boldSystemFont(ofSize: self.baseFontSize)
27-
$0.linkURL = URLRepresentable.tagAttribute("href")
28-
}
29-
30-
let text = "Stile <a href=\"www.facebook.com/agencearcantide/photos/a.346501409312886/346503839312643/?type=3&theater\">link</a>"
31-
let s = StyleGroup(base: baseStyle, ["a" : linkStyle])
32-
self.textView?.attributedText = text.set(style: s)
33-
*/
34-
19+
20+
// self.textView?.attributedText = "ciao ciao " + AttributedString(image: UIImage(named: "rocket")!,
21+
// bounds: CGRect(x: 0, y: -20, width: 25, height: 25)) + "ciao ciao"
22+
//
23+
//
24+
// return
25+
//
3526
let bodyHTML = try! String(contentsOfFile: Bundle.main.path(forResource: "file", ofType: "txt")!)
3627

28+
// Create a set of styles
29+
3730
let headerStyle = Style {
3831
$0.font = UIFont.boldSystemFont(ofSize: self.baseFontSize * 1.15)
3932
$0.lineSpacing = 1
@@ -52,12 +45,22 @@ class ViewController: UIViewController {
5245
let italicStyle = Style {
5346
$0.font = UIFont.italicSystemFont(ofSize: self.baseFontSize)
5447
}
55-
56-
let style = StyleGroup(base: Style {
48+
49+
let uppercasedRed = Style {
50+
$0.font = UIFont.italicSystemFont(ofSize: self.baseFontSize)
51+
$0.color = UIColor.red
52+
$0.textTransforms = [
53+
.uppercase
54+
]
55+
}
56+
57+
// And a group of them
58+
let styleGroup = StyleGroup(base: Style {
5759
$0.font = UIFont.systemFont(ofSize: self.baseFontSize)
5860
$0.lineSpacing = 2
5961
$0.kerning = Kerning.adobe(-15)
6062
}, [
63+
"ur": uppercasedRed,
6164
"h3": headerStyle,
6265
"h4": headerStyle,
6366
"h5": headerStyle,
@@ -73,11 +76,36 @@ class ViewController: UIViewController {
7376
"sup": Style {
7477
$0.font = UIFont.systemFont(ofSize: self.baseFontSize / 1.2)
7578
$0.baselineOffset = Float(self.baseFontSize) / 3.5
76-
}])
77-
78-
self.textView?.attributedText = bodyHTML.set(style: style)
79+
}])
80+
81+
// Apply a custom xml attribute resolver
82+
styleGroup.xmlAttributesResolver = MyXMLDynamicAttributesResolver()
83+
84+
// Render
85+
self.textView?.attributedText = bodyHTML.set(style: styleGroup)
86+
87+
// Accessibility support
7988
if #available(iOS 10.0, *) {
8089
self.textView?.adjustsFontForContentSizeCategory = true
8190
}
91+
8292
}
8393
}
94+
95+
public class MyXMLDynamicAttributesResolver: StandardXMLAttributesResolver {
96+
97+
public override func styleForUnknownXMLTag(_ tag: String, to attributedString: inout AttributedString, attributes: [String : String]?) {
98+
super.styleForUnknownXMLTag(tag, to: &attributedString, attributes: attributes)
99+
100+
if tag == "rainbow" {
101+
let colors = UIColor.randomColors(attributedString.length)
102+
for i in 0..<attributedString.length {
103+
attributedString.add(style: Style({
104+
$0.color = colors[i]
105+
}), range: NSMakeRange(i, 1))
106+
}
107+
}
108+
109+
}
110+
111+
}

ExampleiOS/file.txt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
<strong>Parler du don d'organe n'est plus tabou. Je me renseigne, j'en discute avec mes proches,... et je décide!</strong>
1+
<strong>Parler du don d'organe n'est plus tabou. Je me renseigne, j'en discute avec mes proches,... <rainbow>et je décide!</rainbow></strong>
22

3-
En Belgique, au début des années 2000, le nombre de donneurs d’organes avait tendance à diminuer et les listes d’attente à augmenter considérablement ayant comme corollaire une augmentation de la mortalité des patients inscrits sur les listes d’attente.
3+
<img named="rocket" rect="0,-50,30,30"/>
44

5-
Soucieux de cette situation, en juin 2005, le Ministre en charge de la Santé publique a souhaité mettre sur pied une vaste campagne de sensibilisation entièrement dédiée au don d’organes.
5+
<img url="https://www.macitynet.it/wp-content/uploads/2018/05/video_ApplePark_magg18.jpg"/>
6+
7+
<strong color="#db13f2">En Belgique</strong>, au début des années 2000, le nombre de donneurs d’organes avait tendance à diminuer et les listes d’attente à augmenter considérablement ayant comme corollaire une augmentation de la mortalité des patients inscrits sur les listes d’attente.
8+
9+
Soucieux de cette situation, en juin 2005, le <ur>Ministre en charge de la Santé</ur> publique a souhaité mettre sur pied une vaste campagne de sensibilisation entièrement dédiée au don d’organes.
610

711
Depuis, de nombreuses actions entreprises par le SPF Santé publique viennent renforcer toutes celles qui sont accomplies au quotidien par les coordinateurs de transplantation, les coordinateurs locaux de don, les associations de familles de donneurs, les associations de patients transplantés et ce, depuis de très nombreuses années.
812

0 commit comments

Comments
 (0)