简体   繁体   English

将位于 stackview 内的图像内的图标图像居中

[英]Center an icon image which is inside image which is inside stackview

Hey guys i want to center an image inside an image which is inside stackview.大家好,我想将图像置于堆栈视图内的图像中心。

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

I want anotherimageview centered which is an icon image.我想要另一个图像视图居中,这是一个图标图像。

After adding anotherImageView as a subview of imageView setup its constraints in the way you want.添加anotherImageView作为imageView的子视图后,以您想要的方式设置其约束。

So, after this line:所以,在这一行之后:

imageview.addSubview(anotherimageview)

Add the following:添加以下内容:

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.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM