首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NSMutableAttributedString paragraphStyle不适用

NSMutableAttributedString paragraphStyle不适用
EN

Stack Overflow用户
提问于 2018-04-08 16:10:01
回答 1查看 644关注 0票数 2

我在一个NSMutableAttributedString中添加了一个CATextLayer。除了paragraphStyle之外,所有属性都在应用。对原因有什么想法吗?

谢谢你的帮助。

代码语言:javascript
复制
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)
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-04-08 16:48:21

AFAIK CATextLayer不尊重任何段落风格。您需要一个UITextView来显示段落样式的文本。

编辑:

我猜你想

代码语言:javascript
复制
paragraphStyle.tailIndent = -10

负值是指从尾随边距的距离。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49719954

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档