我们如何把文字放在上面?界面标签

How do we put the text above? UILabel

**

我在做新闻应用。我得到的新闻内容出现在 uilabel 的中间,但我希望它在顶部。

**

private let articleContentLabel: UILabel = {
    let label = UILabel()
    label.numberOfLines = 0
    label.sizeToFit()
    label.lineBreakMode = .byWordWrapping
    label.backgroundColor = .cyan
    label.textColor = UIColor(red: 38/255, green: 50/255, blue: 91/255, alpha: 1)
    label.font = UIFont(name: "SFCompactDisplay-Ultralight", size: 16)
    return label
}()

override func viewDidLoad() {
    super.viewDidLoad()
    view.addSubview(articleContentLabel)   
}

  override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()
        articleContentLabel.frame = CGRect(x: 25,
                                           y: articleImageView.bottom + 40,
                                           width: view.width - 50,
                                           height: 330)
    }

这是我的应用程序中的屏幕截图

进行 UI 布局的首选方法是使用自动布局,而不是设置 frame 属性。您应该设置标签的约束,但不要明确指定其高度,以便可以自动计算它以适应所需的行数。实现应该看起来像这样。

 articleContentLabel.translatesAutoresizingMaskIntoConstraints = false
 articleContentLabel.topAnchor.constraint(equalTo: articleImageView.bottomAnchor).isActive = true
 articleContentLabel.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 25).isActive = true
 articleContentLabel.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -25).isActive = true