0

我试图setImage在我的内部UIButton,但图像在按钮内部显得更小,尽管有“自由空间”,我也设置了contentMode.

按钮:

let noteButton: UIButton = {
    let v = UIButton()
    v.setImage(UIImage(systemName: "pencil"), for: .normal)
    v.tintColor = UIColor.white
    v.imageView?.contentMode = .scaleAspectFit
    v.translatesAutoresizingMaskIntoConstraints = false
    return v
}()

约束:

noteButton.heightAnchor.constraint(equalToConstant: 30).isActive = true
    noteButton.widthAnchor.constraint(equalToConstant: 30).isActive = true
    noteButton.centerYAnchor.constraint(equalTo: itemView.centerYAnchor).isActive = true
    noteButton.leadingAnchor.constraint(equalTo: linkButton.leadingAnchor, constant: 50).isActive = true

结果:

在此处输入图像描述

4

1 回答 1

0

我解决了这个问题。我只需要将这些添加到行中:

v.contentHorizontalAlignment = .fill
v.contentVerticalAlignment = .fill
于 2020-04-04T12:17:00.747 回答