Content Mode | IOS Swift

Luiz Gabriel - Jan 6 - - Dev Community

In this article we will talk about the ways in which elements can be worked with within a view, the value of this property by default comes as .scaleToFill.

We use this property when we want to implement resizable controls. For example, instead of having to redraw every time, we use content mode so that the element adapts as necessary.

.scaleToFill

  • Fills the entire view, so it can lose proportion Image description

.scaleAspectFit

  • Adjusts the content to fit the view while maintaining the aspect ratio, any remaining area is transparent Image description

.scaleAspectFill

  • It fills the view while maintaining the proportion, but the element may go beyond the limits of the view.

Image description

.center

  • Centers the content and maintains the same proportions

Image description

.top

  • Aligns and centers the content at the top of the view

Image description

.bottom

  • Aligns and centers the content at the bottom of the view

Image description

.left

  • Aligns and centers the content on the left side of the view

Image description

.right

  • Aligns and centers the content on the right side of the view

Image description

.topLeft

  • Aligns content to the left at the top of the view

Image description

.topRight

  • Aligns content to the right at the top of the view

Image description

.bottomLeft

  • Aligns content to the left at the bottom of the view

Image description

.bottomRight

  • Aligns content to the right at the bottom of the view

Image description

.redraw

  • Indicates that the view needs to be redrawn every time the size is changed, we use this when the content of the view depends on the view

Image description

Thanks for read this article!

. . . . . . . . .