
fixedSize() // 👈🏻 Ignores the proposed 200x200 points size the applied mask exceeds the view bounds, allowing content bleeding.the view content extends to a 300x300 points rectangle.Therefore masks can allow content bleeding.

Unlike shapes, there's no expectation for views to stay within the natural size of the view they're applied to. The real power over clipping modifiers stands with the opportunity to use any Views as masks. The red border shows the bound of the original view for a visual aid: otherwise, we'd see just a small rectangle floating around. randomElement()!Īlignment should be CaseIterable (FB9581717) In the following example, the mask is 30% the size of the view it's applied to: struct FSView: View. The alignment parameter is particularly useful when the mask and the original view have different sizes. once the mask size is known, it is placed over the view, according to the specified alignment.the modifier proposes to its mask the natural size of the view it's applied to.mask(alignment:_:) positions its mask exactly like an overlay or a background modifier would: For older OSes, the mask declaration is slightly different, but the same concepts are still applied.īesides the naming, this modifier declaration is identical to a couple of other view modifiers we're probably very familiar with, overlay(alignment:_:) and background(alignment:_:): extension View public func overlay(Īlignment: Alignment =. This is a new view modifier using the new view builder pattern. The last masking view modifier that SwiftUI offers is mask(alignment:_:): extension View public func mask(Īlignment: Alignment =. Let's explore SwiftUI masking beyond clipping. the content is either masked or not there's no gray area.


While powerful, clipping has two significant limitations: In View clipping in SwiftUI, we've explored all the ways we can apply clipping masks to views (if you haven't already, read that article first).
SWIFTUI VSTACK ALIGN TOP DOWNLOAD
SeptemFederico Zanetello This article comes with a companion app! Download it here.
