Стиль абзаца NSMutableAttributedString не применяется

Я добавил NSMutableAttributedString в CATextLayer. Применяются все атрибуты, кроме paraStyle. Есть мысли, почему?

Спасибо за помощь.

func createTextLayer() {
    let textLayer = CATextLayer()
    textLayer.frame = CGRect(x: view.center.x - 150, y: view.frame.size.height / 2, width: 300, height: 300)

    let layerText = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce auctor arcu quis velit congue dictum. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce auctor arcu quis velit congue dictum."

    let paragraphStyle = NSMutableParagraphStyle()
    paragraphStyle.firstLineHeadIndent = 10
    paragraphStyle.headIndent = 10
    paragraphStyle.tailIndent = 10
    paragraphStyle.minimumLineHeight = 38
    paragraphStyle.alignment = .center

    let textAttributes: [NSAttributedStringKey : Any] = [
        .font: UIFont(name: "HelveticaNeue-Bold", size: 18)!,
        .foregroundColor: UIColor.white,
        .backgroundColor: UIColor.black,
        .baselineOffset: 10,
        .paragraphStyle: paragraphStyle
        ]

    textLayer.string = NSMutableAttributedString(string: layerText, attributes: textAttributes)
    textLayer.backgroundColor = UIColor.clear.cgColor
    textLayer.isWrapped = true
    textLayer.contentsScale = UIScreen.main.scale
    textView.layer.addSublayer(textLayer)
}

person MT1asli8ghwoi    schedule 08.04.2018    source источник


Ответы (1)


AFAIK CATextLayer не соблюдает стиль абзаца. Вам нужен UITextView для отображения текста в стиле абзаца.

Изменить:

И я думаю, ты хочешь

paragraphStyle.tailIndent = -10

Отрицательные значения означают расстояние от замыкающей границы.

person D. Mika    schedule 08.04.2018
comment
Дерьмо. @Д. Мика, спасибо за понимание и улов -10. - person MT1asli8ghwoi; 09.04.2018