@@ -75,7 +75,28 @@ open class HashtagView: UIView {
7575 // MARK: Hashtag cell padding
7676
7777 @IBInspectable
78- open var tagPadding : CGFloat = 5.0 {
78+ open var tagPaddingLeft : CGFloat = 5.0 {
79+ didSet {
80+ self . collectionView. reloadData ( )
81+ }
82+ }
83+
84+ @IBInspectable
85+ open var tagPaddingRight : CGFloat = 5.0 {
86+ didSet {
87+ self . collectionView. reloadData ( )
88+ }
89+ }
90+
91+ @IBInspectable
92+ open var tagPaddingTop : CGFloat = 5.0 {
93+ didSet {
94+ self . collectionView. reloadData ( )
95+ }
96+ }
97+
98+ @IBInspectable
99+ open var tagPaddingBottom : CGFloat = 5.0 {
79100 didSet {
80101 self . collectionView. reloadData ( )
81102 }
@@ -88,6 +109,13 @@ open class HashtagView: UIView {
88109 }
89110 }
90111
112+ @IBInspectable
113+ open var textSize : CGFloat = 14.0 {
114+ didSet {
115+ self . collectionView. reloadData ( )
116+ }
117+ }
118+
91119 @IBInspectable
92120 open var tagBackgroundColor : UIColor = . lightGray {
93121 didSet {
@@ -179,14 +207,15 @@ open class HashtagView: UIView {
179207
180208 let configuration = HashtagConfiguration ( )
181209
182- configuration. paddingLeft = self . tagPadding
183- configuration. paddingRight = self . tagPadding
184- configuration. paddingTop = self . tagPadding
185- configuration. paddingBottom = self . tagPadding
210+ configuration. paddingLeft = self . tagPaddingLeft
211+ configuration. paddingRight = self . tagPaddingRight
212+ configuration. paddingTop = self . tagPaddingTop
213+ configuration. paddingBottom = self . tagPaddingBottom
186214 configuration. removeButtonSize = self . removeButtonSize
187215 configuration. removeButtonSpacing = self . removeButtonSpacing
188216 configuration. backgroundColor = self . tagBackgroundColor
189217 configuration. cornerRadius = self . tagCornerRadius
218+ configuration. textSize = self . textSize
190219 configuration. textColor = self . tagTextColor
191220
192221 return configuration
@@ -318,24 +347,16 @@ extension HashtagView: UICollectionViewDelegateFlowLayout {
318347
319348 public func collectionView( _ collectionView: UICollectionView , layout collectionViewLayout: UICollectionViewLayout , sizeForItemAt indexPath: IndexPath ) -> CGSize {
320349 let hashtag : HashTag = self . hashtags [ indexPath. item]
321- let textDimensions = hashtag. text. sizeOfString ( usingFont: UIFont . systemFont ( ofSize: 14.0 ) )
350+ let wordSize = hashtag. text. sizeOfString ( usingFont: UIFont . systemFont ( ofSize: self . textSize ) )
322351
323352 var calculatedHeight = CGFloat ( )
324353 var calculatedWidth = CGFloat ( )
325354
326- let configuration = makeConfiguration ( )
327-
328- calculatedHeight = configuration. paddingTop + textDimensions. height + configuration. paddingBottom
355+ calculatedHeight = self . tagPaddingTop + wordSize. height + self . tagPaddingBottom
356+ calculatedWidth = self . tagPaddingLeft + wordSize. width + self . tagPaddingRight + 1
329357
330358 if hashtag. isRemovable {
331- calculatedWidth =
332- configuration. paddingLeft
333- + textDimensions. width
334- + configuration. removeButtonSpacing
335- + configuration. removeButtonSize
336- + configuration. paddingRight
337- } else {
338- calculatedWidth = configuration. paddingLeft + textDimensions. width + configuration. paddingRight
359+ calculatedWidth += self . removeButtonSize + self . removeButtonSpacing
339360 }
340361 return CGSize ( width: calculatedWidth, height: calculatedHeight)
341362 }
0 commit comments