【发布时间】:2020-11-12 23:59:33
【问题描述】:
所以,我在我的 stackView 中添加了一些文本 (UITextView) 并居中于顶部。我还添加了一个 UIImageView,它可以很好地位于我的 UITextView 下。好吧,它没有。由于某种原因,图像完全覆盖了文本。如果我删除图像,文本会在顶部中心很好地恢复。在堆栈分布和对齐方面玩了很多,但没有运气。不知道我错过了什么:(。感谢任何帮助!
我将 UITextView 和 UIIMageView 都添加到了栈中。
这是我的代码:
//stack
let stack: UIStackView = {
let stack = UIStackView()
stack.translatesAutoresizingMaskIntoConstraints = false
stack.axis = .vertical
stack.spacing = 5
stack.distribution = .fillProportionally
stack.alignment = .fill
return stack
}()
//text
fileprivate let title: UITextView = {
let title = UITextView()
title.translatesAutoresizingMaskIntoConstraints = false
title.contentMode = .scaleAspectFit
title.layer.cornerRadius = 10
title.backgroundColor = .darkGray
title.font = UIFont(name: "Megrim-Regular", size: 17)
title.textColor = .white
title.textAlignment = .center
return title
}()
//image
let image: UIImageView = {
let image = UIImageView()
image.image = UIImage(named: "demoPic.jpg")
image.translatesAutoresizingMaskIntoConstraints = false
image.frame = CGRect(x: 0, y: 0, width: 50, height: 50)
return image
}()
【问题讨论】:
标签: ios swift iphone user-interface stackview