问题:
黄色部分是子视图(子视图是UIImageView,superview是UIView。),它的大小与其superview(灰色部分)相同,我应该怎么做要解决这个问题吗?
屏幕图片:
以下是代码:
var linkedMemory = Memory(masteryLevel: 1, algorithm: Algorithm.algorithm1.chooseAlgorithm(), forgetRatio: 0, lastStudyTime: Date(), front: #imageLiteral(resourceName: "Ideas-Yellow"), back: #imageLiteral(resourceName: "Ideas-Blue"))
var frontView: UIView {
let front = showContent(of: linkedMemory.front)
return front
}
convenience init(memory: Memory) {
self.init(frame: CGRect())
self.linkedMemory = memory
self.setupView()
}
override init(frame: CGRect) {
super.init(frame: frame)
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
setupView()
}
func setupView() {
self.layer.cornerRadius = 20
self.layer.shadowRadius = 12
self.layer.shadowOpacity = 0.15
self.layer.masksToBounds = true
addGesture()
sizeNAddSubview(view: frontView)
}
func sizeNAddSubview(view: UIView) {
view.frame.size = self.bounds.size
addSubview(view)
}
func showContent(of linkenMemory: Any) -> UIView {
var contentView = UIView()
if let content = linkenMemory as? UIImage {
let imageView = UIImageView()
imageView.image = content
contentView = imageView
}
if let content = linkedMemory as? String {
let label = UILabel()
label.centerYAnchor.constraint(equalTo: self.centerYAnchor).isActive = true
label.centerXAnchor.constraint(equalTo: self.centerXAnchor).isActive = true
let text = content
label.text = text
contentView = label
}
return contentView
}
以下是限制因素: