Skip to content

Commit

Permalink
feat(tagcelllayout): add helper method to calculate text width
Browse files Browse the repository at this point in the history
  • Loading branch information
riteshhgupta committed Jun 12, 2016
1 parent 0bb7a72 commit bac3513
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Source/TagCellLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,16 @@ public class TagCellLayout: UICollectionViewLayout {
delegate?.tagCellLayoutTagFixHeight(self) ?? 0
)
}

public class func textWidth(text: String, font: UIFont) -> CGFloat {
let padding: CGFloat = 4 // this number is independent of font and is required to compensate the inaccuracy of sizeToFit calculation!
let label = UILabel()
label.text = text
label.font = font
label.sizeToFit()
let frame = label.frame
return (frame.width + padding)
}
}

//MARK: - Private Methods
Expand Down

0 comments on commit bac3513

Please sign in to comment.