File tree Expand file tree Collapse file tree 4 files changed +56
-1
lines changed Expand file tree Collapse file tree 4 files changed +56
-1
lines changed Original file line number Diff line number Diff line change
1
+ {
2
+ "info" : {
3
+ "version" : 1 ,
4
+ "author" : " xcode"
5
+ }
6
+ }
Original file line number Diff line number Diff line change
1
+ {
2
+ "images" : [
3
+ {
4
+ "idiom" : " universal" ,
5
+ "scale" : " 1x"
6
+ },
7
+ {
8
+ "idiom" : " universal" ,
9
+ "filename" : " icons8-scissors-26.png" ,
10
+ "scale" : " 2x"
11
+ },
12
+ {
13
+ "idiom" : " universal" ,
14
+ "scale" : " 3x"
15
+ }
16
+ ],
17
+ "info" : {
18
+ "version" : 1 ,
19
+ "author" : " xcode"
20
+ }
21
+ }
Original file line number Diff line number Diff line change @@ -146,6 +146,33 @@ func stringWithBoldItalicUnderline() -> NSAttributedString {
146
146
return str
147
147
}
148
148
149
+ func stringWithImage( ) -> NSAttributedString {
150
+
151
+ let str = " Running with <img id= \" scissors \" ></img>! " . style ( tags: [ ] )
152
+
153
+ let mutableAttrStr = NSMutableAttributedString ( attributedString: str. attributedString)
154
+
155
+ var locationShift = 0
156
+ for detection in str. detections {
157
+ switch detection. type {
158
+ case . tag( let tag) :
159
+ if let imageId = tag. attributes [ " id " ] {
160
+ let textAttachment = NSTextAttachment ( )
161
+ textAttachment. image = UIImage ( named: imageId)
162
+ let imageAttrStr = NSAttributedString ( attachment: textAttachment)
163
+ let nsrange = NSRange . init ( detection. range, in: mutableAttrStr. string)
164
+ mutableAttrStr. insert ( imageAttrStr, at: nsrange. location + locationShift)
165
+ locationShift += 1
166
+ }
167
+ default :
168
+ break
169
+ }
170
+ }
171
+
172
+
173
+ return mutableAttrStr
174
+ }
175
+
149
176
func allSnippets( ) -> [ NSAttributedString ] {
150
177
return [
151
178
stringWithAtributikaLogo ( ) ,
@@ -160,7 +187,8 @@ func allSnippets() -> [NSAttributedString] {
160
187
stringWithTagAndHashtag ( ) ,
161
188
stringWithUnorderedList ( ) ,
162
189
stringWithHref ( ) ,
163
- stringWithBoldItalicUnderline ( )
190
+ stringWithBoldItalicUnderline ( ) ,
191
+ stringWithImage ( )
164
192
]
165
193
}
166
194
You can’t perform that action at this time.
0 commit comments