Skip to content

Commit cdbba81

Browse files
committed
Add playground with example
1 parent a08773f commit cdbba81

File tree

6 files changed

+89
-3
lines changed

6 files changed

+89
-3
lines changed

.gitignore

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
# macOS
12
.DS_Store
2-
/SwiftRichString/SwiftRichString.xcodeproj/xcuserdata/danielemargutti.xcuserdatad
3-
/SwiftRichString/SwiftRichString.xcodeproj/project.xcworkspace/xcuserdata/danielemargutti.xcuserdatad
4-
/SwiftRichString.xcworkspace/xcuserdata/danielemargutti.xcuserdatad
3+
4+
# Xcode
5+
xcuserdata
56
*.xcuserstate
7+
*.xctimeline
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
2+
import UIKit
3+
import SwiftRichString
4+
import PlaygroundSupport
5+
6+
// Create your own styles
7+
8+
let normal = Style {
9+
$0.font = SystemFonts.Helvetica_Light.font(size: 15)
10+
}
11+
12+
let bold = Style {
13+
$0.font = SystemFonts.Helvetica_Bold.font(size: 20)
14+
$0.color = UIColor.red
15+
$0.backColor = UIColor.yellow
16+
}
17+
18+
let italic = normal.byAdding {
19+
$0.traitVariants = .italic
20+
}
21+
22+
// Create a group which contains your style, each identified by a tag.
23+
let myGroup = StyleGroup(base: normal, ["bold": bold, "italic": italic])
24+
25+
// Use tags in your plain string
26+
let str = "Hello <bold>Daniele!</bold>. You're ready to <italic>play with us!</italic>"
27+
28+
let attributedStringController = AttributedStringController()
29+
PlaygroundPage.current.liveView = attributedStringController
30+
31+
attributedStringController.attributedString = str.set(style: myGroup)
32+
33+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
import UIKit
3+
4+
public class AttributedStringController: UIViewController {
5+
6+
public var attributedString: NSAttributedString? {
7+
get {
8+
return textView?.attributedText
9+
}
10+
set {
11+
textView?.attributedText = newValue
12+
}
13+
}
14+
15+
private var textView: UITextView?
16+
17+
public override func loadView() {
18+
let view = UIView()
19+
view.backgroundColor = .white
20+
21+
let textView = UITextView()
22+
textView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
23+
textView.attributedText = attributedString
24+
view.addSubview(textView)
25+
self.textView = textView
26+
27+
self.view = view
28+
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2+
<playground version='5.0' target-platform='ios'>
3+
<timeline fileName='timeline.xctimeline'/>
4+
</playground>

SwiftRichString.xcworkspace/contents.xcworkspacedata

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>IDEDidComputeMac32BitWarning</key>
6+
<true/>
7+
</dict>
8+
</plist>

0 commit comments

Comments
 (0)