質問編集履歴

1

UIViewへのextensionを記入していませんでしたので、追記しました。

2021/08/07 02:14

投稿

daiishi
daiishi

スコア6

test CHANGED
File without changes
test CHANGED
@@ -286,6 +286,50 @@
286
286
 
287
287
 
288
288
 
289
+ extension UIView {
290
+
291
+ func fillSuperview(padding: UIEdgeInsets = .zero) {
292
+
293
+ translatesAutoresizingMaskIntoConstraints = false
294
+
295
+ if let superviewTopAnchor = superview?.topAnchor {
296
+
297
+ topAnchor.constraint(equalTo: superviewTopAnchor, constant: padding.top).isActive = true
298
+
299
+ }
300
+
301
+
302
+
303
+ if let superviewBottomAnchor = superview?.bottomAnchor {
304
+
305
+ bottomAnchor.constraint(equalTo: superviewBottomAnchor, constant: -padding.bottom).isActive = true
306
+
307
+ }
308
+
309
+
310
+
311
+ if let superviewLeadingAnchor = superview?.leadingAnchor {
312
+
313
+ leadingAnchor.constraint(equalTo: superviewLeadingAnchor, constant: padding.left).isActive = true
314
+
315
+ }
316
+
317
+
318
+
319
+ if let superviewTrailingAnchor = superview?.trailingAnchor {
320
+
321
+ trailingAnchor.constraint(equalTo: superviewTrailingAnchor, constant: -padding.right).isActive = true
322
+
323
+ }
324
+
325
+ }
326
+
327
+ }
328
+
329
+
330
+
331
+
332
+
289
333
  ```
290
334
 
291
335
  ```Swift