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