Я пытаюсь имитировать скриншот ниже, используя NSAttributedString
вместо полноценного UICollectionView
.
![enter image description here](https://i.stack.imgur.com/H0KmO.png)
Япочти там, но я не могу получить правильное расстояние между белыми линиями и разрывы строк: ![enter image description here](https://i.stack.imgur.com/Sp6mn.png)
Вот мой код:
let attributedText = myList.reduce(into: NSMutableAttributedString()) { result, next in
let text = NSMutableAttributedString(string: " ")
text.append(NSMutableAttributedString(string: next))
text.append(NSMutableAttributedString(string: " "))
text.addAttributes(
[
.font: UIFont.systemFont(ofSize: 12),
.foregroundColor: UIColor.darkGrey,
.backgroundColor: UIColor.lightGray
],
range: NSRange(location: 0, length: text.length)
)
result.append(text)
guard myList.last != next else { return }
result.append(NSMutableAttributedString(string: " "))
}
attributedText.addAttributes(
[
.paragraphStyle: NSMutableParagraphStyle().with {
$0.alignment = .center
$0.lineHeightMultiple = 2
$0.lineSpacing = 12
}
],
range: NSRange(location: 0, length: attributedText.length)
)
attributedText.append(NSMutableAttributedString(string: "\n"))
myLabel.attributedText = attributedText
Существуют ли атрибуты, которые могутсправиться с этим, чтобы он выглядел как первый скриншот?