Reputation: 5741
Problem:
The yellow part is the subview( The subview is UIImageView, and the superview is UIView. ), its size is suppose to be the same as its superview (the gray part), what should I do to fix this?
Screen Images:
Here's the code:
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
}
Here are the constraints:
Upvotes: 0
Views: 900
Reputation: 288
Your flash card view is UIView.And you want to make it full screen, then follow this.
Upvotes: 0
Reputation: 1384
You can either give constraints as equal height and equal width of superview
[or]
If you are setting this view before layout pass, the size of superview will not be the actual size, so you've to move the code to either viewDidAppear()
or viewDidLayoutSubviews()
Upvotes: 1