我正在尝试将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
结果:
我已解决此问题。我只需要将这些添加到行中即可:
v.contentHorizontalAlignment = .fill
v.contentVerticalAlignment = .fill