質問編集履歴
2
基礎を見直すと解決できます。
test
CHANGED
File without changes
|
test
CHANGED
@@ -2,406 +2,10 @@
|
|
2
2
|
|
3
3
|
オートレイアウト の原因を調べられるサイトで調査したところ、
|
4
4
|
|
5
|
-
[https://www.wtfautolayout.com](https://www.wtfautolayout.com)
|
6
5
|
|
7
|
-
**StackView's top edge should equal Label's bottom edge.**
|
8
|
-
|
9
|
-
**StackView's top edge should equal Label's bottom edge plus 8.**
|
10
6
|
|
11
7
|
また、Xcodeでは
|
12
|
-
|
13
|
-
```ここに言語を入力
|
14
|
-
|
15
|
-
Unable to simultaneously satisfy constraints.
|
16
|
-
|
17
|
-
Probably at least one of the constraints in the following list is one you don't want.
|
18
|
-
|
19
|
-
Try this:
|
20
|
-
|
21
|
-
(1) look at each constraint and try to figure out which you don't expect;
|
22
|
-
|
23
|
-
(2) find the code that added the unwanted constraint or constraints and fix it.
|
24
|
-
|
25
|
-
(
|
26
|
-
|
27
|
-
"<NSLayoutConstraint:0x600003595590 V:[UILabel:0x7fed456218b0]-(0)-[UIStackView:0x7fed45556500] (active)>",
|
28
|
-
|
29
|
-
"<NSLayoutConstraint:0x600003595400 V:[UILabel:0x7fed456218b0]-(8)-[UIStackView:0x7fed45556500] (active)>"
|
30
|
-
|
31
|
-
)
|
32
|
-
|
33
|
-
```
|
34
8
|
|
35
9
|
とスタックの底とラベルの上がおかしいので、8pt加えたりしたのですが、変わりません。
|
36
10
|
|
37
11
|
他に何を加えればいいのかわからないため、どなたかご教授ください。お願いします。
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
```ここに言語を入力
|
44
|
-
|
45
|
-
// 問題のセル
|
46
|
-
|
47
|
-
class TweetHeader: UICollectionReusableView {
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
lazy var profileImageView: UIImageView = {
|
52
|
-
|
53
|
-
let iv = UIImageView()
|
54
|
-
|
55
|
-
return iv
|
56
|
-
|
57
|
-
}()
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
let fullnameLabel: UILabel = {
|
62
|
-
|
63
|
-
let label = UILabel()
|
64
|
-
|
65
|
-
return label
|
66
|
-
|
67
|
-
}()
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
let usernameLabel: UILabel = {
|
72
|
-
|
73
|
-
let label = UILabel()
|
74
|
-
|
75
|
-
return label
|
76
|
-
|
77
|
-
}()
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
let captionLabel: UILabel = {
|
82
|
-
|
83
|
-
let label = UILabel()
|
84
|
-
|
85
|
-
label.font = UIFont.systemFont(ofSize: 14)
|
86
|
-
|
87
|
-
label.numberOfLines = 0
|
88
|
-
|
89
|
-
return label
|
90
|
-
|
91
|
-
}()
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
let dateLabel: UILabel = {
|
96
|
-
|
97
|
-
let label = UILabel()
|
98
|
-
|
99
|
-
return label
|
100
|
-
|
101
|
-
}()
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
let replyLabel: ActiveLabel = {
|
106
|
-
|
107
|
-
let label = ActiveLabel()
|
108
|
-
|
109
|
-
return label
|
110
|
-
|
111
|
-
}()
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
var imageURLs = List<CellImageURL>()
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
var imageContainer = UIStackView()
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
lazy var statsView: UIView = {
|
124
|
-
|
125
|
-
let view = UIView()
|
126
|
-
|
127
|
-
let divider1 = UIView()
|
128
|
-
|
129
|
-
view.addSubview(divider1)
|
130
|
-
|
131
|
-
divider1.anchor(top: view.topAnchor, left: view.leftAnchor, right: view.rightAnchor, paddingLeft: 8, height: 1.0)
|
132
|
-
|
133
|
-
let stack = UIStackView(arrangedSubviews: [commentButton, retweetButton, likeButton, shareButton])
|
134
|
-
|
135
|
-
stack.axis = .horizontal
|
136
|
-
|
137
|
-
stack.spacing = 72
|
138
|
-
|
139
|
-
view.addSubview(stack)
|
140
|
-
|
141
|
-
stack.centerY(inView: view)
|
142
|
-
|
143
|
-
stack.anchor(left: view.leftAnchor, paddingLeft: 60)
|
144
|
-
|
145
|
-
let divider2 = UIView()
|
146
|
-
|
147
|
-
divider2.backgroundColor = .systemGroupedBackground
|
148
|
-
|
149
|
-
view.addSubview(divider2)
|
150
|
-
|
151
|
-
divider2.anchor(left: view.leftAnchor, bottom: view.bottomAnchor, right: view.rightAnchor, paddingLeft: 8, height: 1.0)
|
152
|
-
|
153
|
-
return view
|
154
|
-
|
155
|
-
}()
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
lazy var commentButton: UIButton = {
|
162
|
-
|
163
|
-
let button = createButton(withImageName: "outline_mode_comment_black_24pt_1x")
|
164
|
-
|
165
|
-
button.addTarget(self, action: #selector(handleReplyTapped), for: .touchUpInside)
|
166
|
-
|
167
|
-
return button
|
168
|
-
|
169
|
-
}()
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
lazy var retweetButton: UIButton = {
|
174
|
-
|
175
|
-
let button = UIButton(type: .system)
|
176
|
-
|
177
|
-
button.setImage(UIImage(named: "outline_autorenew_black_24pt_1x"), for: .normal)
|
178
|
-
|
179
|
-
button.tintColor = .darkGray
|
180
|
-
|
181
|
-
button.setDimensions(width: 20, height: 20)
|
182
|
-
|
183
|
-
button.addTarget(self, action: #selector(handleRetweetTapped), for: .touchUpInside)
|
184
|
-
|
185
|
-
return button
|
186
|
-
|
187
|
-
}()
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
lazy var likeButton: UIButton = {
|
192
|
-
|
193
|
-
let button = createButton(withImageName: "like_unselected")
|
194
|
-
|
195
|
-
button.addTarget(self, action: #selector(handleLikeTapped), for: .touchUpInside)
|
196
|
-
|
197
|
-
return button
|
198
|
-
|
199
|
-
}()
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
lazy var shareButton: UIButton = {
|
204
|
-
|
205
|
-
let button = createButton(withImageName: "outline_share_black_24pt_1x")
|
206
|
-
|
207
|
-
button.addTarget(self, action: #selector(handleShareTapped), for: .touchUpInside)
|
208
|
-
|
209
|
-
return button
|
210
|
-
|
211
|
-
}()
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
override init(frame: CGRect) {
|
216
|
-
|
217
|
-
super.init(frame: frame)
|
218
|
-
|
219
|
-
configure()
|
220
|
-
|
221
|
-
}
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
required init?(coder: NSCoder) {
|
226
|
-
|
227
|
-
fatalError("init(coder:) has not been implemented")
|
228
|
-
|
229
|
-
}
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
override func prepareForReuse() {
|
234
|
-
|
235
|
-
super.prepareForReuse()
|
236
|
-
|
237
|
-
captionLabel.text = ""
|
238
|
-
|
239
|
-
replyLabel.text = ""
|
240
|
-
|
241
|
-
fullnameLabel.attributedText = nil
|
242
|
-
|
243
|
-
usernameLabel.attributedText = nil
|
244
|
-
|
245
|
-
profileImageView.image = nil
|
246
|
-
|
247
|
-
imageURLs = List<CellImageURL>()
|
248
|
-
|
249
|
-
imageContainer.removeFromSuperview()
|
250
|
-
|
251
|
-
}
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
func configure(){
|
256
|
-
|
257
|
-
backgroundColor = UIColor(named: "Mode")
|
258
|
-
|
259
|
-
if currentUser.user.profileImage != nil {
|
260
|
-
|
261
|
-
profileImageView.image = UIImage(data: currentUser.user.profileImage!)
|
262
|
-
|
263
|
-
} else {
|
264
|
-
|
265
|
-
profileImageView.image = UIImage(named: "placeholderImg")
|
266
|
-
|
267
|
-
}
|
268
|
-
|
269
|
-
addSubview(profileImageView)
|
270
|
-
|
271
|
-
profileImageView.anchor(top: topAnchor, left: leftAnchor, paddingTop: 16, paddingLeft: 16)
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
let labelStack = UIStackView(arrangedSubviews: [fullnameLabel, usernameLabel])
|
276
|
-
|
277
|
-
labelStack.axis = .horizontal
|
278
|
-
|
279
|
-
labelStack.spacing = 3
|
280
|
-
|
281
|
-
addSubview(labelStack)
|
282
|
-
|
283
|
-
labelStack.anchor(top: profileImageView.topAnchor, left: profileImageView.rightAnchor, paddingTop: 4, paddingLeft: 16)
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
addSubview(captionLabel)
|
288
|
-
|
289
|
-
captionLabel.anchor(top: profileImageView.bottomAnchor, left: leftAnchor, right: rightAnchor,paddingTop: 16, paddingLeft: 16, paddingRight: 16)
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
addSubview(dateLabel)
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
if !imageURLs.isEmpty {
|
298
|
-
|
299
|
-
let vstack1 = UIStackView()
|
300
|
-
|
301
|
-
vstack1.axis = .vertical
|
302
|
-
|
303
|
-
vstack1.spacing = 2
|
304
|
-
|
305
|
-
vstack1.distribution = .fillEqually
|
306
|
-
|
307
|
-
vstack1.contentHuggingPriority(for: NSLayoutConstraint.Axis(rawValue: 750)!)
|
308
|
-
|
309
|
-
let vstack2 = UIStackView()
|
310
|
-
|
311
|
-
vstack2.axis = .vertical
|
312
|
-
|
313
|
-
vstack2.spacing = 2
|
314
|
-
|
315
|
-
vstack2.distribution = .fillEqually
|
316
|
-
|
317
|
-
vstack2.isHidden = imageURLs.count == 1
|
318
|
-
|
319
|
-
vstack2.contentHuggingPriority(for: NSLayoutConstraint.Axis(rawValue: 750)!)
|
320
|
-
|
321
|
-
imageContainer = UIStackView(arrangedSubviews: [vstack1, vstack2])
|
322
|
-
|
323
|
-
imageContainer.axis = .horizontal
|
324
|
-
|
325
|
-
imageContainer.spacing = 2
|
326
|
-
|
327
|
-
imageContainer.distribution = .fillEqually
|
328
|
-
|
329
|
-
addSubview(imageContainer)
|
330
|
-
|
331
|
-
imageContainer.leadingAnchor.constraint(equalTo: captionLabel.leadingAnchor).isActive = true
|
332
|
-
|
333
|
-
imageContainer.topAnchor.constraint(equalTo: captionLabel.bottomAnchor).isActive = true
|
334
|
-
|
335
|
-
imageContainer.anchor(top: captionLabel.bottomAnchor, left: captionLabel.leftAnchor, bottom: dateLabel.topAnchor, right: self.rightAnchor, paddingTop: 8, paddingLeft: 0, paddingBottom: 0, paddingRight: 8, height: 160)
|
336
|
-
|
337
|
-
imageContainer.contentHuggingPriority(for: NSLayoutConstraint.Axis(rawValue: 750)!)
|
338
|
-
|
339
|
-
dateLabel.leadingAnchor.constraint(equalTo: captionLabel.leadingAnchor).isActive = true
|
340
|
-
|
341
|
-
dateLabel.topAnchor.constraint(equalTo: imageContainer.bottomAnchor).isActive = true
|
342
|
-
|
343
|
-
// ここ
|
344
|
-
|
345
|
-
dateLabel.anchor(top: imageContainer.bottomAnchor, left: leftAnchor, paddingTop: 0, paddingLeft: 16)
|
346
|
-
|
347
|
-
imageURLs.enumerated().forEach { index, image in
|
348
|
-
|
349
|
-
let path = fileInDocumentsDirectory(filename: image.imageURL)
|
350
|
-
|
351
|
-
let imageView = UIImageView()
|
352
|
-
|
353
|
-
imageView.isUserInteractionEnabled = true
|
354
|
-
|
355
|
-
imageView.image = UIImage(contentsOfFile: path)
|
356
|
-
|
357
|
-
imageView.tag = index
|
358
|
-
|
359
|
-
if index % 2 == 0 {
|
360
|
-
|
361
|
-
vstack1.addArrangedSubview(imageView)
|
362
|
-
|
363
|
-
} else {
|
364
|
-
|
365
|
-
vstack2.addArrangedSubview(imageView)
|
366
|
-
|
367
|
-
}
|
368
|
-
|
369
|
-
imageView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(imageViewTappedGesture(_:))))
|
370
|
-
|
371
|
-
}
|
372
|
-
|
373
|
-
} else {
|
374
|
-
|
375
|
-
dateLabel.anchor(top: captionLabel.bottomAnchor, left: leftAnchor, paddingTop: 20, paddingLeft: 16)
|
376
|
-
|
377
|
-
}
|
378
|
-
|
379
|
-
addSubview(statsView)
|
380
|
-
|
381
|
-
statsView.anchor(top: dateLabel.bottomAnchor, left: leftAnchor, right: rightAnchor, paddingTop: 12, height: 40)
|
382
|
-
|
383
|
-
}
|
384
|
-
|
385
|
-
}
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
```
|
390
|
-
|
391
|
-
### VC
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
```ここに言語を入力
|
396
|
-
|
397
|
-
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
|
398
|
-
|
399
|
-
let height = calcSize(width: view.frame.width, text: tweets.caption).height
|
400
|
-
|
401
|
-
let imageContainerHeight: CGFloat = tweets.imageURLs.isEmpty ? 0 : 160
|
402
|
-
|
403
|
-
return CGSize(width: view.frame.width, height: height + 170 + imageContainerHeight)
|
404
|
-
|
405
|
-
}
|
406
|
-
|
407
|
-
```
|
1
エラー内容と、VCを修正いたしました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -10,7 +10,9 @@
|
|
10
10
|
|
11
11
|
また、Xcodeでは
|
12
12
|
|
13
|
+
```ここに言語を入力
|
14
|
+
|
13
|
-
|
15
|
+
Unable to simultaneously satisfy constraints.
|
14
16
|
|
15
17
|
Probably at least one of the constraints in the following list is one you don't want.
|
16
18
|
|
@@ -22,15 +24,13 @@
|
|
22
24
|
|
23
25
|
(
|
24
26
|
|
25
|
-
"<NSLayoutConstraint:0x600000bcf7f0 V:[UILabel:0x7fbccce18af0]-(20)-[UILabel:0x7fbccce18d60] (active)>",
|
26
|
-
|
27
|
-
"<NSLayoutConstraint:0x60000
|
27
|
+
"<NSLayoutConstraint:0x600003595590 V:[UILabel:0x7fed456218b0]-(0)-[UIStackView:0x7fed45556500] (active)>",
|
28
|
-
|
28
|
+
|
29
|
-
"<NSLayoutConstraint:0x600000
|
29
|
+
"<NSLayoutConstraint:0x600003595400 V:[UILabel:0x7fed456218b0]-(8)-[UIStackView:0x7fed45556500] (active)>"
|
30
|
-
|
31
|
-
|
30
|
+
|
32
|
-
|
33
|
-
)
|
31
|
+
)
|
32
|
+
|
33
|
+
```
|
34
34
|
|
35
35
|
とスタックの底とラベルの上がおかしいので、8pt加えたりしたのですが、変わりません。
|
36
36
|
|
@@ -42,7 +42,7 @@
|
|
42
42
|
|
43
43
|
```ここに言語を入力
|
44
44
|
|
45
|
-
|
45
|
+
// 問題のセル
|
46
46
|
|
47
47
|
class TweetHeader: UICollectionReusableView {
|
48
48
|
|
@@ -52,22 +52,6 @@
|
|
52
52
|
|
53
53
|
let iv = UIImageView()
|
54
54
|
|
55
|
-
iv.contentMode = .scaleAspectFill
|
56
|
-
|
57
|
-
iv.clipsToBounds = true
|
58
|
-
|
59
|
-
iv.setDimensions(width: 48, height: 48)
|
60
|
-
|
61
|
-
iv.layer.cornerRadius = 48 / 2
|
62
|
-
|
63
|
-
iv.backgroundColor = .twitterBlue
|
64
|
-
|
65
|
-
let tap = UITapGestureRecognizer(target: self, action: #selector(handleProfileImageTapped))
|
66
|
-
|
67
|
-
iv.addGestureRecognizer(tap)
|
68
|
-
|
69
|
-
iv.isUserInteractionEnabled = true
|
70
|
-
|
71
55
|
return iv
|
72
56
|
|
73
57
|
}()
|
@@ -78,8 +62,6 @@
|
|
78
62
|
|
79
63
|
let label = UILabel()
|
80
64
|
|
81
|
-
label.font = UIFont.boldSystemFont(ofSize: 14)
|
82
|
-
|
83
65
|
return label
|
84
66
|
|
85
67
|
}()
|
@@ -90,10 +72,6 @@
|
|
90
72
|
|
91
73
|
let label = UILabel()
|
92
74
|
|
93
|
-
label.font = UIFont.boldSystemFont(ofSize: 14)
|
94
|
-
|
95
|
-
label.textColor = .lightGray
|
96
|
-
|
97
75
|
return label
|
98
76
|
|
99
77
|
}()
|
@@ -118,12 +96,6 @@
|
|
118
96
|
|
119
97
|
let label = UILabel()
|
120
98
|
|
121
|
-
label.font = UIFont.systemFont(ofSize: 14)
|
122
|
-
|
123
|
-
label.textColor = .lightGray
|
124
|
-
|
125
|
-
label.textAlignment = .left
|
126
|
-
|
127
99
|
return label
|
128
100
|
|
129
101
|
}()
|
@@ -134,12 +106,6 @@
|
|
134
106
|
|
135
107
|
let label = ActiveLabel()
|
136
108
|
|
137
|
-
label.textColor = .lightGray
|
138
|
-
|
139
|
-
label.font = UIFont.systemFont(ofSize: 12)
|
140
|
-
|
141
|
-
label.mentionColor = .twitterBlue
|
142
|
-
|
143
109
|
return label
|
144
110
|
|
145
111
|
}()
|
@@ -158,286 +124,284 @@
|
|
158
124
|
|
159
125
|
let view = UIView()
|
160
126
|
|
127
|
+
let divider1 = UIView()
|
128
|
+
|
129
|
+
view.addSubview(divider1)
|
130
|
+
|
131
|
+
divider1.anchor(top: view.topAnchor, left: view.leftAnchor, right: view.rightAnchor, paddingLeft: 8, height: 1.0)
|
132
|
+
|
133
|
+
let stack = UIStackView(arrangedSubviews: [commentButton, retweetButton, likeButton, shareButton])
|
134
|
+
|
135
|
+
stack.axis = .horizontal
|
136
|
+
|
137
|
+
stack.spacing = 72
|
138
|
+
|
139
|
+
view.addSubview(stack)
|
140
|
+
|
141
|
+
stack.centerY(inView: view)
|
142
|
+
|
143
|
+
stack.anchor(left: view.leftAnchor, paddingLeft: 60)
|
144
|
+
|
145
|
+
let divider2 = UIView()
|
146
|
+
|
147
|
+
divider2.backgroundColor = .systemGroupedBackground
|
148
|
+
|
149
|
+
view.addSubview(divider2)
|
150
|
+
|
151
|
+
divider2.anchor(left: view.leftAnchor, bottom: view.bottomAnchor, right: view.rightAnchor, paddingLeft: 8, height: 1.0)
|
152
|
+
|
153
|
+
return view
|
154
|
+
|
155
|
+
}()
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
lazy var commentButton: UIButton = {
|
162
|
+
|
163
|
+
let button = createButton(withImageName: "outline_mode_comment_black_24pt_1x")
|
164
|
+
|
165
|
+
button.addTarget(self, action: #selector(handleReplyTapped), for: .touchUpInside)
|
166
|
+
|
167
|
+
return button
|
168
|
+
|
169
|
+
}()
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
lazy var retweetButton: UIButton = {
|
174
|
+
|
175
|
+
let button = UIButton(type: .system)
|
176
|
+
|
177
|
+
button.setImage(UIImage(named: "outline_autorenew_black_24pt_1x"), for: .normal)
|
178
|
+
|
179
|
+
button.tintColor = .darkGray
|
180
|
+
|
181
|
+
button.setDimensions(width: 20, height: 20)
|
182
|
+
|
183
|
+
button.addTarget(self, action: #selector(handleRetweetTapped), for: .touchUpInside)
|
184
|
+
|
185
|
+
return button
|
186
|
+
|
187
|
+
}()
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
lazy var likeButton: UIButton = {
|
192
|
+
|
193
|
+
let button = createButton(withImageName: "like_unselected")
|
194
|
+
|
195
|
+
button.addTarget(self, action: #selector(handleLikeTapped), for: .touchUpInside)
|
196
|
+
|
197
|
+
return button
|
198
|
+
|
199
|
+
}()
|
200
|
+
|
201
|
+
|
202
|
+
|
203
|
+
lazy var shareButton: UIButton = {
|
204
|
+
|
205
|
+
let button = createButton(withImageName: "outline_share_black_24pt_1x")
|
206
|
+
|
207
|
+
button.addTarget(self, action: #selector(handleShareTapped), for: .touchUpInside)
|
208
|
+
|
209
|
+
return button
|
210
|
+
|
211
|
+
}()
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
override init(frame: CGRect) {
|
216
|
+
|
217
|
+
super.init(frame: frame)
|
218
|
+
|
219
|
+
configure()
|
220
|
+
|
221
|
+
}
|
222
|
+
|
223
|
+
|
224
|
+
|
225
|
+
required init?(coder: NSCoder) {
|
226
|
+
|
227
|
+
fatalError("init(coder:) has not been implemented")
|
228
|
+
|
229
|
+
}
|
230
|
+
|
231
|
+
|
232
|
+
|
233
|
+
override func prepareForReuse() {
|
234
|
+
|
235
|
+
super.prepareForReuse()
|
236
|
+
|
237
|
+
captionLabel.text = ""
|
238
|
+
|
239
|
+
replyLabel.text = ""
|
240
|
+
|
241
|
+
fullnameLabel.attributedText = nil
|
242
|
+
|
243
|
+
usernameLabel.attributedText = nil
|
244
|
+
|
245
|
+
profileImageView.image = nil
|
246
|
+
|
247
|
+
imageURLs = List<CellImageURL>()
|
248
|
+
|
249
|
+
imageContainer.removeFromSuperview()
|
250
|
+
|
251
|
+
}
|
252
|
+
|
253
|
+
|
254
|
+
|
255
|
+
func configure(){
|
256
|
+
|
257
|
+
backgroundColor = UIColor(named: "Mode")
|
258
|
+
|
259
|
+
if currentUser.user.profileImage != nil {
|
260
|
+
|
261
|
+
profileImageView.image = UIImage(data: currentUser.user.profileImage!)
|
262
|
+
|
263
|
+
} else {
|
264
|
+
|
265
|
+
profileImageView.image = UIImage(named: "placeholderImg")
|
266
|
+
|
267
|
+
}
|
268
|
+
|
269
|
+
addSubview(profileImageView)
|
270
|
+
|
271
|
+
profileImageView.anchor(top: topAnchor, left: leftAnchor, paddingTop: 16, paddingLeft: 16)
|
272
|
+
|
161
273
|
|
162
274
|
|
275
|
+
let labelStack = UIStackView(arrangedSubviews: [fullnameLabel, usernameLabel])
|
276
|
+
|
163
|
-
let
|
277
|
+
labelStack.axis = .horizontal
|
164
|
-
|
278
|
+
|
165
|
-
|
279
|
+
labelStack.spacing = 3
|
166
|
-
|
280
|
+
|
167
|
-
|
281
|
+
addSubview(labelStack)
|
282
|
+
|
168
|
-
|
283
|
+
labelStack.anchor(top: profileImageView.topAnchor, left: profileImageView.rightAnchor, paddingTop: 4, paddingLeft: 16)
|
284
|
+
|
285
|
+
|
286
|
+
|
287
|
+
addSubview(captionLabel)
|
288
|
+
|
169
|
-
|
289
|
+
captionLabel.anchor(top: profileImageView.bottomAnchor, left: leftAnchor, right: rightAnchor,paddingTop: 16, paddingLeft: 16, paddingRight: 16)
|
170
290
|
|
171
291
|
|
172
292
|
|
173
|
-
let stack = UIStackView(arrangedSubviews: [commentButton, retweetButton, likeButton, shareButton])
|
174
|
-
|
175
|
-
|
293
|
+
addSubview(dateLabel)
|
176
|
-
|
177
|
-
stack.spacing = 72
|
178
294
|
|
179
295
|
|
180
296
|
|
181
|
-
|
182
|
-
|
183
|
-
stack
|
184
|
-
|
185
|
-
stack.a
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
v
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
r
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
b
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
}
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
configure()
|
297
|
+
if !imageURLs.isEmpty {
|
298
|
+
|
299
|
+
let vstack1 = UIStackView()
|
300
|
+
|
301
|
+
vstack1.axis = .vertical
|
302
|
+
|
303
|
+
vstack1.spacing = 2
|
304
|
+
|
305
|
+
vstack1.distribution = .fillEqually
|
306
|
+
|
307
|
+
vstack1.contentHuggingPriority(for: NSLayoutConstraint.Axis(rawValue: 750)!)
|
308
|
+
|
309
|
+
let vstack2 = UIStackView()
|
310
|
+
|
311
|
+
vstack2.axis = .vertical
|
312
|
+
|
313
|
+
vstack2.spacing = 2
|
314
|
+
|
315
|
+
vstack2.distribution = .fillEqually
|
316
|
+
|
317
|
+
vstack2.isHidden = imageURLs.count == 1
|
318
|
+
|
319
|
+
vstack2.contentHuggingPriority(for: NSLayoutConstraint.Axis(rawValue: 750)!)
|
320
|
+
|
321
|
+
imageContainer = UIStackView(arrangedSubviews: [vstack1, vstack2])
|
322
|
+
|
323
|
+
imageContainer.axis = .horizontal
|
324
|
+
|
325
|
+
imageContainer.spacing = 2
|
326
|
+
|
327
|
+
imageContainer.distribution = .fillEqually
|
328
|
+
|
329
|
+
addSubview(imageContainer)
|
330
|
+
|
331
|
+
imageContainer.leadingAnchor.constraint(equalTo: captionLabel.leadingAnchor).isActive = true
|
332
|
+
|
333
|
+
imageContainer.topAnchor.constraint(equalTo: captionLabel.bottomAnchor).isActive = true
|
334
|
+
|
335
|
+
imageContainer.anchor(top: captionLabel.bottomAnchor, left: captionLabel.leftAnchor, bottom: dateLabel.topAnchor, right: self.rightAnchor, paddingTop: 8, paddingLeft: 0, paddingBottom: 0, paddingRight: 8, height: 160)
|
336
|
+
|
337
|
+
imageContainer.contentHuggingPriority(for: NSLayoutConstraint.Axis(rawValue: 750)!)
|
338
|
+
|
339
|
+
dateLabel.leadingAnchor.constraint(equalTo: captionLabel.leadingAnchor).isActive = true
|
340
|
+
|
341
|
+
dateLabel.topAnchor.constraint(equalTo: imageContainer.bottomAnchor).isActive = true
|
342
|
+
|
343
|
+
// ここ
|
344
|
+
|
345
|
+
dateLabel.anchor(top: imageContainer.bottomAnchor, left: leftAnchor, paddingTop: 0, paddingLeft: 16)
|
346
|
+
|
347
|
+
imageURLs.enumerated().forEach { index, image in
|
348
|
+
|
349
|
+
let path = fileInDocumentsDirectory(filename: image.imageURL)
|
350
|
+
|
351
|
+
let imageView = UIImageView()
|
352
|
+
|
353
|
+
imageView.isUserInteractionEnabled = true
|
354
|
+
|
355
|
+
imageView.image = UIImage(contentsOfFile: path)
|
356
|
+
|
357
|
+
imageView.tag = index
|
358
|
+
|
359
|
+
if index % 2 == 0 {
|
360
|
+
|
361
|
+
vstack1.addArrangedSubview(imageView)
|
362
|
+
|
363
|
+
} else {
|
364
|
+
|
365
|
+
vstack2.addArrangedSubview(imageView)
|
366
|
+
|
367
|
+
}
|
368
|
+
|
369
|
+
imageView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(imageViewTappedGesture(_:))))
|
370
|
+
|
371
|
+
}
|
372
|
+
|
373
|
+
} else {
|
374
|
+
|
375
|
+
dateLabel.anchor(top: captionLabel.bottomAnchor, left: leftAnchor, paddingTop: 20, paddingLeft: 16)
|
376
|
+
|
377
|
+
}
|
378
|
+
|
379
|
+
addSubview(statsView)
|
380
|
+
|
381
|
+
statsView.anchor(top: dateLabel.bottomAnchor, left: leftAnchor, right: rightAnchor, paddingTop: 12, height: 40)
|
268
382
|
|
269
383
|
}
|
270
384
|
|
271
|
-
|
385
|
+
}
|
386
|
+
|
387
|
+
|
388
|
+
|
272
|
-
|
389
|
+
```
|
390
|
+
|
391
|
+
### VC
|
392
|
+
|
393
|
+
|
394
|
+
|
395
|
+
```ここに言語を入力
|
396
|
+
|
397
|
+
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
|
398
|
+
|
273
|
-
|
399
|
+
let height = calcSize(width: view.frame.width, text: tweets.caption).height
|
274
|
-
|
400
|
+
|
275
|
-
|
401
|
+
let imageContainerHeight: CGFloat = tweets.imageURLs.isEmpty ? 0 : 160
|
402
|
+
|
403
|
+
return CGSize(width: view.frame.width, height: height + 170 + imageContainerHeight)
|
276
404
|
|
277
405
|
}
|
278
406
|
|
279
|
-
|
280
|
-
|
281
|
-
override func prepareForReuse() {
|
282
|
-
|
283
|
-
super.prepareForReuse()
|
284
|
-
|
285
|
-
captionLabel.text = ""
|
286
|
-
|
287
|
-
replyLabel.text = ""
|
288
|
-
|
289
|
-
fullnameLabel.attributedText = nil
|
290
|
-
|
291
|
-
usernameLabel.attributedText = nil
|
292
|
-
|
293
|
-
profileImageView.image = nil
|
294
|
-
|
295
|
-
imageURLs = List<CellImageURL>()
|
296
|
-
|
297
|
-
imageContainer.removeFromSuperview()
|
298
|
-
|
299
|
-
}
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
func configure(){
|
304
|
-
|
305
|
-
backgroundColor = UIColor(named: "Mode")
|
306
|
-
|
307
|
-
if currentUser.user.profileImage != nil {
|
308
|
-
|
309
|
-
profileImageView.image = UIImage(data: currentUser.user.profileImage!)
|
310
|
-
|
311
|
-
} else {
|
312
|
-
|
313
|
-
profileImageView.image = UIImage(named: "placeholderImg")
|
314
|
-
|
315
|
-
}
|
316
|
-
|
317
|
-
addSubview(profileImageView)
|
318
|
-
|
319
|
-
profileImageView.anchor(top: topAnchor, left: leftAnchor, paddingTop: 16, paddingLeft: 16)
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
let labelStack = UIStackView(arrangedSubviews: [fullnameLabel, usernameLabel])
|
324
|
-
|
325
|
-
labelStack.axis = .horizontal
|
326
|
-
|
327
|
-
labelStack.spacing = 3
|
328
|
-
|
329
|
-
addSubview(labelStack)
|
330
|
-
|
331
|
-
labelStack.anchor(top: profileImageView.topAnchor, left: profileImageView.rightAnchor, paddingTop: 4, paddingLeft: 16)
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
addSubview(captionLabel)
|
336
|
-
|
337
|
-
captionLabel.anchor(top: profileImageView.bottomAnchor, left: leftAnchor, right: rightAnchor,paddingTop: 16, paddingLeft: 16, paddingRight: 16)
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
addSubview(dateLabel)
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
if !imageURLs.isEmpty {
|
346
|
-
|
347
|
-
let vstack1 = UIStackView()
|
348
|
-
|
349
|
-
vstack1.axis = .vertical
|
350
|
-
|
351
|
-
vstack1.spacing = 2
|
352
|
-
|
353
|
-
vstack1.distribution = .fillEqually
|
354
|
-
|
355
|
-
vstack1.contentHuggingPriority(for: NSLayoutConstraint.Axis(rawValue: 750)!)
|
356
|
-
|
357
|
-
let vstack2 = UIStackView()
|
358
|
-
|
359
|
-
vstack2.axis = .vertical
|
360
|
-
|
361
|
-
vstack2.spacing = 2
|
362
|
-
|
363
|
-
vstack2.distribution = .fillEqually
|
364
|
-
|
365
|
-
vstack2.isHidden = imageURLs.count == 1
|
366
|
-
|
367
|
-
vstack2.contentHuggingPriority(for: NSLayoutConstraint.Axis(rawValue: 750)!)
|
368
|
-
|
369
|
-
imageContainer = UIStackView(arrangedSubviews: [vstack1, vstack2])
|
370
|
-
|
371
|
-
imageContainer.axis = .horizontal
|
372
|
-
|
373
|
-
imageContainer.spacing = 2
|
374
|
-
|
375
|
-
imageContainer.distribution = .fillEqually
|
376
|
-
|
377
|
-
addSubview(imageContainer)
|
378
|
-
|
379
|
-
imageContainer.leadingAnchor.constraint(equalTo: captionLabel.leadingAnchor).isActive = true
|
380
|
-
|
381
|
-
imageContainer.topAnchor.constraint(equalTo: captionLabel.bottomAnchor).isActive = true
|
382
|
-
|
383
|
-
imageContainer.anchor(top: captionLabel.bottomAnchor, left: captionLabel.leftAnchor, bottom: dateLabel.topAnchor, right: self.rightAnchor, paddingTop: 8, paddingLeft: 0, paddingBottom: 0, paddingRight: 8, height: 160)
|
384
|
-
|
385
|
-
imageContainer.contentHuggingPriority(for: NSLayoutConstraint.Axis(rawValue: 750)!)
|
386
|
-
|
387
|
-
dateLabel.leadingAnchor.constraint(equalTo: captionLabel.leadingAnchor).isActive = true
|
388
|
-
|
389
|
-
dateLabel.topAnchor.constraint(equalTo: imageContainer.bottomAnchor).isActive = true
|
390
|
-
|
391
|
-
// ここ
|
392
|
-
|
393
|
-
dateLabel.anchor(top: imageContainer.bottomAnchor, left: leftAnchor, paddingTop: 0, paddingLeft: 16)
|
394
|
-
|
395
|
-
imageURLs.enumerated().forEach { index, image in
|
396
|
-
|
397
|
-
let path = fileInDocumentsDirectory(filename: image.imageURL)
|
398
|
-
|
399
|
-
let imageView = UIImageView()
|
400
|
-
|
401
|
-
imageView.isUserInteractionEnabled = true
|
402
|
-
|
403
|
-
imageView.image = UIImage(contentsOfFile: path)
|
404
|
-
|
405
|
-
imageView.tag = index
|
406
|
-
|
407
|
-
if index % 2 == 0 {
|
408
|
-
|
409
|
-
vstack1.addArrangedSubview(imageView)
|
410
|
-
|
411
|
-
} else {
|
412
|
-
|
413
|
-
vstack2.addArrangedSubview(imageView)
|
414
|
-
|
415
|
-
}
|
416
|
-
|
417
|
-
imageView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(imageViewTappedGesture(_:))))
|
418
|
-
|
419
|
-
}
|
420
|
-
|
421
|
-
} else {
|
422
|
-
|
423
|
-
dateLabel.anchor(top: captionLabel.bottomAnchor, left: leftAnchor, paddingTop: 20, paddingLeft: 16)
|
424
|
-
|
425
|
-
}
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
addSubview(statsView)
|
430
|
-
|
431
|
-
statsView.anchor(top: dateLabel.bottomAnchor, left: leftAnchor, right: rightAnchor, paddingTop: 12, height: 40)
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
}
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
}
|
440
|
-
|
441
|
-
|
442
|
-
|
443
407
|
```
|