Самый простой метод - просто установить линии меток как 0
@ oddK - Не устанавливать ширину как коллекцию width / 2, вместо этого установите ширину, основываясь на текстовом содержимом,
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let width = collectionView.frame.width
let lblWidth = "My text".getWidth(withConstrainedHeight: CGFloat(53), font: UIFont.systemFont(ofSize: 14))
return CGSize(width: lblWidth, height: 53)
}
//Get Width of content in label
func getWidth(withConstrainedHeight:CGFloat, font: UIFont) -> CGFloat {
let viewRect = CGSize(width: .greatestFiniteMagnitude, height: withConstrainedHeight)
let getFrame = self.boundingRect(with: viewRect, options: .usesLineFragmentOrigin, attributes: [NSAttributedString.Key.font : font], context: nil)
return getFrame.size.width
}