How to keep a round imageView round using auto layout?

后端 未结 15 1417
悲&欢浪女
悲&欢浪女 2020-12-01 06:22

How do I turn a rectangular image view into a circular image view that can hold shape in auto layout without setting width and height restraints? Thereby allowing the imageV

15条回答
  •  余生分开走
    2020-12-01 06:38

    It seems when you add one view as a subview of another that netted view will not necessarily have the same height as its superview. That's what the problem seems like. The solution is to not add your imageView as a subview, but have it on top of your backgroundView. In the image below I'm using a UILabel as my backgroundView.

    Also in your case, when you're setting the cornerRadius use this: let radius: CGFloat = self.bounds.size.height / 2.0.

提交回复
热议问题