相关疑难解决方法(0)

Swift NSAttributedString修剪

我想在我的NSAttributedString(修剪它)的前面和末尾骑上白色空间.我不能简单地将其转换为字符串并进行修剪,因为其中有图像(附件).我该怎么做?

cocoa-touch ios swift

15
推荐指数
2
解决办法
3970
查看次数

如何使用 UIStackView 中的属性文本删除 UILabel 的底部填充

我想在 UIStackview 中删除带有属性文本的 UILabel 的底部填充。

在此处输入图片说明

我找到了这个解决方案How to remove the extra padding under a one line UILabel。这适用于普通文本,但不适用于属性文本。

   let textLabel = UILabel()
        textLabel.translatesAutoresizingMaskIntoConstraints = false
        textLabel.text = "What is a chemical property and how can you observe it?"
        textLabel.numberOfLines = 0
        textLabel.lineBreakMode = .byWordWrapping
        textLabel.backgroundColor = .lightGray
        mainStackView.addArrangedSubview(textLabel)

        let textLabel2 = UILabel()
        textLabel2.translatesAutoresizingMaskIntoConstraints = false

        let html = "<html lang=\"en\"><head><meta charset=\"UTF-8\"></head><body><div style=\"font-size:36;\"><p>What is a <em>chemical property</em> and how can you observe it?</p></div></body></html>"

        let data = Data(html.utf8)

        if let …
Run Code Online (Sandbox Code Playgroud)

nsattributedstring uilabel ios uistackview swift3

1
推荐指数
1
解决办法
457
查看次数