Pick the fix
A view must stay perfectly circular whatever size Auto Layout gives it. Where do you set the corner radius?
Hint 1 of 1
When are bounds final?
Choose an answer, then open Show answer below to check it.
Show answer
Answer: A Override layoutSubviews, call super, then set layer.cornerRadius = bounds.height / 2
Correct. Bounds are final there and it reruns when the size changes.
Why not the others?
- B In
init. Bounds are usually zero at init time. - C In the view controller's
viewDidLoad. Layout hasn't run yet, so the size isn't final. - D In
draw(_:). draw is for custom drawing, and it is expensive; it isn't layer configuration.