-3

enter image description hereenter image description here

I have added the two images(Both are different width iPhone one is 375width and another is 414width, I know design is messing up because of the height is given according to the width of the view ). As you can see I have a table view inside the table view there is a collection view horizontally scrolling and that collection view's cell is not showing perfectly in all devices. Because I'm giving height according to the width of the UIScreen(CGSize(width: UIScreen.main.bounds.size.width/2+120, height:UIScreen.main.bounds.size.width/2-200). Can Anybody let me know to set the aspect ratio of this view programmatically, I tried to find the tutorial about aspect ratio but there no completely written or explained tutorial.

Cœur
  • 37,241
  • 25
  • 195
  • 267

1 Answers1

0

You set the UIView's geometry using the view's .frame property.

See: https://developer.apple.com/documentation/uikit/uiview/1622621-frame

.frame takes a CGRect (https://developer.apple.com/documentation/coregraphics/cgrect), which has x, y, width, and height arguments. The ratio of the width to the height is the aspect ratio.

Note that if you're laying out your UIView using the storyboard, the view's constraints can also mess with the geometry, even overriding the geometry set in the .frame property

Michael Shulman
  • 643
  • 5
  • 6