Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 148
Expand file tree
/
Copy pathAutoSizingContainerView.swift
More file actions
Latest commit
68 lines (55 loc) · 1.83 KB
/
Copy pathAutoSizingContainerView.swift
File metadata and controls
68 lines (55 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import UIKit
finalclassAutoSizingContainerView:UIView{
privateletimageView=UIImageView()
privateletfirstTextLabel=UILabel()
privateletsecondTextLabel=UILabel()
privateletmargin:CGFloat=10
@Proxy(\AutoSizingContainerView.imageView.image)
varimage:UIImage?{
didSet {
setNeedsLayout()
}
}
@Proxy(\AutoSizingContainerView.firstTextLabel.text)
varfirstText:String?{
didSet {
setNeedsLayout()
}
}
@Proxy(\AutoSizingContainerView.secondTextLabel.text)
varsecondText:String?{
didSet {
setNeedsLayout()
}
}
init(){
super.init(frame:CGRect.zero)
configureView()
}
requiredinit?(coder:NSCoder){
fatalError("init(coder:) has not been implemented")
}
privatefunc configureView(){
imageView.clipsToBounds =true
imageView.contentMode =.scaleAspectFill
addSubview(imageView)
firstTextLabel.numberOfLines =0
firstTextLabel.backgroundColor =UIColor.orange.withAlphaComponent(0.3)
addSubview(firstTextLabel)
secondTextLabel.numberOfLines =0
secondTextLabel.backgroundColor =UIColor.green.withAlphaComponent(0.3)
addSubview(secondTextLabel)
}
overridefunc layoutSubviews(){
super.layoutSubviews()
performLayout()
}
privatefunc performLayout(){
imageView.pin.top().horizontally().sizeToFit(.width).margin(margin)
firstTextLabel.pin.below(of: imageView).horizontally().sizeToFit(.width).margin(margin)
secondTextLabel.pin.below(of: firstTextLabel).horizontally().sizeToFit(.width).margin(margin)
}
overridefunc sizeThatFits(_ size:CGSize)->CGSize{
autoSizeThatFits(size, layoutClosure: performLayout)
}
}