質問編集履歴

2

解決方法を追記

2018/10/31 07:09

投稿

HNSZ
HNSZ

スコア33

test CHANGED
File without changes
test CHANGED
@@ -53,3 +53,127 @@
53
53
  }
54
54
 
55
55
  ```
56
+
57
+
58
+
59
+ ■解決済み
60
+
61
+ 下記方法にて解決いたしました。皆様ご回答ありがとうございました。
62
+
63
+
64
+
65
+ コード修正①
66
+
67
+ ```
68
+
69
+ override func viewDidLoad() {
70
+
71
+ super.viewDidLoad()
72
+
73
+
74
+
75
+ //image
76
+
77
+ let imageurl = NSURL(string: "(*画像URL記載)")
78
+
79
+ let imageData = try? NSData(contentsOf: imageurl! as URL,options: NSData.ReadingOptions.mappedIfSafe)
80
+
81
+ let contentimage = UIImage(data:imageData! as Data)
82
+
83
+ let imageView = UIImageView(image:contentimage)
84
+
85
+  
86
+
87
+      //修正 
88
+
89
+      imageView.contentMode = .scaleAspectFill
90
+
91
+ imageView.clipsToBounds = true
92
+
93
+
94
+
95
+ self.contentView.addSubview(imageView)
96
+
97
+  
98
+
99
+      //追記
100
+
101
+      contentView.addFitConstraints(to: imageView)
102
+
103
+ }
104
+
105
+ ```
106
+
107
+
108
+
109
+ コード追記
110
+
111
+ ```
112
+
113
+ extension UIView {
114
+
115
+ func addFitConstraints(to: UIView) {
116
+
117
+ to.translatesAutoresizingMaskIntoConstraints = false
118
+
119
+ self.addConstraint(NSLayoutConstraint(item: to,
120
+
121
+ attribute: .top,
122
+
123
+ relatedBy: .equal,
124
+
125
+ toItem: self,
126
+
127
+ attribute: .top,
128
+
129
+ multiplier: 1.0,
130
+
131
+ constant: 0))
132
+
133
+ self.addConstraint(NSLayoutConstraint(item: to,
134
+
135
+ attribute: .leading,
136
+
137
+ relatedBy: .equal,
138
+
139
+ toItem: self,
140
+
141
+ attribute: .leading,
142
+
143
+ multiplier: 1.0,
144
+
145
+ constant: 0))
146
+
147
+ self.addConstraint(NSLayoutConstraint(item: self,
148
+
149
+ attribute: .bottom,
150
+
151
+ relatedBy: .equal,
152
+
153
+ toItem: to,
154
+
155
+ attribute: .bottom,
156
+
157
+ multiplier: 1.0,
158
+
159
+ constant: 0))
160
+
161
+ self.addConstraint(NSLayoutConstraint(item: self,
162
+
163
+ attribute: .trailing,
164
+
165
+ relatedBy: .equal,
166
+
167
+ toItem: to,
168
+
169
+ attribute: .trailing,
170
+
171
+ multiplier: 1.0,
172
+
173
+ constant: 0))
174
+
175
+ }
176
+
177
+ }
178
+
179
+ ```

1

コード記載方法を変更しました

2018/10/31 07:08

投稿

HNSZ
HNSZ

スコア33

test CHANGED
File without changes
test CHANGED
@@ -24,6 +24,8 @@
24
24
 
25
25
  ・コード
26
26
 
27
+ ```
28
+
27
29
  override func viewDidLoad() {
28
30
 
29
31
  super.viewDidLoad()
@@ -49,3 +51,5 @@
49
51
  }
50
52
 
51
53
  }
54
+
55
+ ```