2
2
// Created by Yam on 2024/6/9.
3
3
//
4
4
5
+ import Kingfisher
5
6
import UIKit
6
7
7
8
class ReplyDetailViewController : UIViewController {
9
+ private var scrollView : UIScrollView !
10
+ private var contentView : UIView !
8
11
private var titleLabel : UILabel !
9
- private var replyLabel : UILabel !
12
+ private var replyLabel : UIButton !
10
13
private var replyCollectionView : UICollectionView !
14
+ private var imageStackView : UIStackView !
11
15
12
- var reply : Replys . Reply
16
+ private let reply : Replys . Reply
13
17
14
18
init ( reply: Replys . Reply ) {
15
19
self . reply = reply
@@ -25,41 +29,85 @@ class ReplyDetailViewController: UIViewController {
25
29
super. viewDidLoad ( )
26
30
27
31
setUpViews ( )
28
- replyLabel. text = reply. content. message
32
+ replyLabel. setTitle ( reply. content. message, for: . normal)
33
+ reply. content. pictures? . compactMap { URL ( string: $0. img_src) } . forEach { url in
34
+ let imageView = UIImageView ( )
35
+ imageView. kf. setImage ( with: url)
36
+ imageView. contentMode = . scaleAspectFit
37
+ imageView. snp. makeConstraints { make in
38
+ make. height. lessThanOrEqualTo ( 500 )
39
+ }
40
+ imageStackView. addArrangedSubview ( imageView)
41
+ }
29
42
}
30
43
31
44
// MARK: - Private
32
45
33
46
private func setUpViews( ) {
47
+ scrollView = {
48
+ let scroll = UIScrollView ( )
49
+ view. addSubview ( scroll)
50
+ scroll. snp. makeConstraints { make in
51
+ make. edges. equalToSuperview ( )
52
+ }
53
+ return scroll
54
+ } ( )
55
+
56
+ contentView = {
57
+ let view = UIView ( )
58
+ scrollView. addSubview ( view)
59
+ view. snp. makeConstraints { make in
60
+ make. edges. equalToSuperview ( )
61
+ make. width. equalToSuperview ( )
62
+ }
63
+ return view
64
+ } ( )
65
+
34
66
titleLabel = {
35
67
let label = UILabel ( )
36
- self . view . addSubview ( label)
68
+ contentView . addSubview ( label)
37
69
label. font = . boldSystemFont( ofSize: 60 )
38
70
label. text = " 评论 "
39
71
40
72
label. snp. makeConstraints { make in
41
73
make. centerX. equalToSuperview ( )
42
- make. top. equalTo ( view . safeAreaLayoutGuide )
74
+ make. top. equalToSuperview ( ) . offset ( 20 )
43
75
}
44
76
45
77
return label
46
78
} ( )
47
79
48
80
replyLabel = {
49
- let label = UILabel ( )
50
- self . view. addSubview ( label)
51
- label. numberOfLines = 0
52
- label. font = . preferredFont( forTextStyle: . headline)
53
-
81
+ let label = UIButton ( )
82
+ contentView. addSubview ( label)
83
+ label. titleLabel? . numberOfLines = 0
84
+ label. titleLabel? . textAlignment = . left
85
+ label. titleLabel? . font = . preferredFont( forTextStyle: . headline)
86
+ label. contentHorizontalAlignment = . left
54
87
label. snp. makeConstraints { make in
55
88
make. top. equalTo ( self . titleLabel. snp. bottom) . offset ( 60 )
56
- make. leading. equalTo ( self . view . snp. leadingMargin)
57
- make. trailing. equalTo ( self . view . snp. trailingMargin)
89
+ make. leading. equalTo ( contentView . snp. leadingMargin)
90
+ make. trailing. equalTo ( contentView . snp. trailingMargin)
58
91
}
59
92
60
93
return label
61
94
} ( )
62
95
96
+ imageStackView = {
97
+ let stackView = UIStackView ( )
98
+ stackView. axis = . horizontal
99
+ stackView. distribution = . fillEqually
100
+ stackView. spacing = 10
101
+ contentView. addSubview ( stackView) // 改为添加到 contentView
102
+
103
+ stackView. snp. makeConstraints { make in
104
+ make. top. equalTo ( self . replyLabel. snp. bottom) . offset ( 60 )
105
+ make. leading. equalTo ( contentView. snp. leadingMargin)
106
+ make. trailing. equalTo ( contentView. snp. trailingMargin)
107
+ }
108
+ return stackView
109
+ } ( )
110
+
63
111
replyCollectionView = {
64
112
let flowLayout = UICollectionViewFlowLayout ( )
65
113
flowLayout. itemSize = CGSize ( width: 582 , height: 360 )
@@ -68,14 +116,15 @@ class ReplyDetailViewController: UIViewController {
68
116
flowLayout. minimumInteritemSpacing = 10
69
117
70
118
let collectionView = UICollectionView ( frame: . zero, collectionViewLayout: flowLayout)
71
- self . view . addSubview ( collectionView)
119
+ contentView . addSubview ( collectionView)
72
120
collectionView. dataSource = self
73
121
collectionView. delegate = self
74
122
collectionView. register ( UINib ( nibName: ReplyCell . identifier, bundle: nil ) , forCellWithReuseIdentifier: ReplyCell . identifier)
75
123
76
124
collectionView. snp. makeConstraints { make in
77
125
make. leading. trailing. equalToSuperview ( )
78
- make. top. equalTo ( self . replyLabel. snp. bottom) . offset ( 60 )
126
+ make. top. equalTo ( self . imageStackView. snp. bottom) . offset ( 60 )
127
+ make. height. width. equalTo ( 360 )
79
128
make. bottom. equalToSuperview ( )
80
129
}
81
130
0 commit comments