Updated for Xcode 14.2
SwiftUI’s scaleEffect()
modifier lets us increase or decrease the size of a view freely.
For example, we could make a text view five times its regular size like this:
Text("Up we go")
.scaleEffect(5)
.frame(width: 300, height: 300)
Download this as an Xcode project
You can scale the X and Y dimensions independently if you want, allowing you to squash views like this:
Text("Up we go")
.scaleEffect(x: 1, y: 5)
.frame(width: 300, height: 300)
Download this as an Xcode project
If you want more control, you can specify an anchor for your scaling like this:
VStack {
Text("Up we go")
.scaleEffect(2, anchor: .bottomTrailing)
Text("Up we go")
}
Download this as an Xcode project
That makes the text view twice its regular size, scaled from the bottom-right corner.
Tip: Scaling up a view won’t cause it to be redrawn at its new size, only stretched up or down. This means small text will look fuzzy, and small images might look pixellated or blurry.
SAVE 50% To celebrate WWDC23, all our books and bundles are half price, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.
Link copied to your pasteboard.