@@ -87,14 +87,53 @@ final class CustomCalendarExampleController: DayViewController {
87
87
let duration = Int . random ( in: 60 ... 160 )
88
88
event. dateInterval = DateInterval ( start: workingDate, duration: TimeInterval ( duration * 60 ) )
89
89
90
- var info = data. randomElement ( ) ?? [ ]
90
+ let info = data. randomElement ( ) ?? [ ]
91
+ let attributedInfo = NSMutableAttributedString (
92
+ string: info. reduce ( " " , { $0 + $1 + " \n " } ) ,
93
+ attributes: [ . font: UIFont . systemFont ( ofSize: 12 , weight: . semibold) ]
94
+ )
91
95
92
96
let timezone = dayView. calendar. timeZone
93
97
print ( timezone)
94
98
95
- info. append ( dateIntervalFormatter. string ( from: event. dateInterval. start, to: event. dateInterval. end) )
96
- event. text = info. reduce ( " " , { $0 + $1 + " \n " } )
97
- event. color = colors. randomElement ( ) ?? . red
99
+ let durationText = dateIntervalFormatter. string (
100
+ from: event. dateInterval. start,
101
+ to: event. dateInterval. end
102
+ )
103
+
104
+ let color = colors. randomElement ( ) ?? . red
105
+
106
+ let durationAttributedText : NSMutableAttributedString = {
107
+ var attributedString : NSMutableAttributedString !
108
+ if #available( iOS 13 . 0 , * ) {
109
+ let clockIcon = NSTextAttachment ( )
110
+ let config = UIImage . SymbolConfiguration ( pointSize: 12 , weight: . thin, scale: . small)
111
+ let image = UIImage ( systemName: " clock " , withConfiguration: config)
112
+ clockIcon. image = image
113
+ let text = NSMutableAttributedString ( attachment: clockIcon)
114
+ attributedString = text
115
+ } else {
116
+ attributedString = NSMutableAttributedString ( string: " " )
117
+ }
118
+ attributedString. addAttribute (
119
+ . paragraphStyle,
120
+ value: {
121
+ let paragraphStyle = NSMutableParagraphStyle ( )
122
+ paragraphStyle. paragraphSpacingBefore = 5
123
+ return paragraphStyle
124
+ } ( ) ,
125
+ range: NSRange ( location: 0 , length: attributedString. string. count)
126
+ )
127
+ return attributedString
128
+ } ( )
129
+ let attributedDuration = NSAttributedString (
130
+ string: String ( format: " %@ " , durationText) ,
131
+ attributes: [ . font: UIFont . systemFont ( ofSize: 11 , weight: . light) ]
132
+ )
133
+ durationAttributedText. append ( attributedDuration)
134
+ attributedInfo. append ( durationAttributedText)
135
+ event. attributedText = attributedInfo
136
+ event. color = color
98
137
event. isAllDay = Bool . random ( )
99
138
event. lineBreakMode = . byTruncatingTail
100
139
0 commit comments