gpt4 book ai didi

ios - NSMutableAttributedString paragraphStyle 不适用

转载 作者:行者123 更新时间:2023-11-28 07:50:55 26 4
gpt4 key购买 nike

我已经将 NSMutableAttributedString 添加到 CATextLayer。除了 paragraphStyle 之外的所有属性都适用。有什么想法吗?

感谢您的帮助。

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)
}

最佳答案

AFAIK CATextLayer 不遵循任何段落样式。您需要一个 UITextView 来显示具有段落样式的文本。

编辑:

我猜你想要

paragraphStyle.tailIndent = -10

负值表示距尾边距的距离。

关于ios - NSMutableAttributedString paragraphStyle 不适用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49719954/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com