[英]Center an icon image which is inside image which is inside 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.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.