将stackview内部的图标图像居中



嘿,伙计们,我想把一个图像放在stackview中的图像中心。

let stackview = UIStackView()
stackview.addArrangedSubview(imageview)
imageview.addSubview(anotherimageview)

我想要一个以图标图像为中心的图像视图。

添加anotherImageView作为imageView的子视图后,按照您想要的方式设置其约束。

所以,在这行之后:

imageview.addSubview(anotherimageview)

添加以下内容:

anotherimageview.translatesAutoresizingMaskIntoConstraints = false
anotherimageview.centerXAnchor.constraint(equalTo: imageview.centerXAnchor).isActive = true
anotherimageview.centerYAnchor.constraint(equalTo: imageview.centerYAnchor).isActive = true
// And do the same for the width and height constraints.

最新更新