将图标图像置于stackview内部的图像内部

问题描述 投票:-2回答:1

大家好,我想将图像居中在stackview内部的图像中。

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

我想让另一个图像视图居中,这是一个图标图像。

ios swift uiimageview uistackview
1个回答
0
投票

在将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.
© www.soinside.com 2019 - 2024. All rights reserved.