diff --git a/Sources/ImageMod/ImageModable.swift b/Sources/ImageMod/ImageModable.swift index c9982e7..ac204d9 100644 --- a/Sources/ImageMod/ImageModable.swift +++ b/Sources/ImageMod/ImageModable.swift @@ -79,7 +79,8 @@ public extension ImageModable { // MARK: Stack - func hStack(_ image: ImageModable, spacing: CGFloat = 0, alignment: UIStackView.Alignment = .center) -> ImageModable { + func hStack(_ image: ImageModable?, spacing: CGFloat = 0, alignment: UIStackView.Alignment = .center) -> ImageModable { + guard let image = image else { return self } let rect = image.canvasSize.vAlign(in: canvasSize, alignment: alignment) return self .padded(right: rect.maxX + spacing) @@ -91,7 +92,8 @@ public extension ImageModable { ) } - func vStack(_ image: ImageModable, spacing: CGFloat = 0, alignment: UIStackView.Alignment = .center) -> ImageModable { + func vStack(_ image: ImageModable?, spacing: CGFloat = 0, alignment: UIStackView.Alignment = .center) -> ImageModable { + guard let image = image else { return self } let rect = image.canvasSize.hAlign(in: canvasSize, alignment: alignment) return self .padded(bottom: rect.maxY + spacing) @@ -103,7 +105,8 @@ public extension ImageModable { ) } - func zStack(_ overlay: ImageModable, alignment: UIView.ContentMode = .center) -> ImageModable { + func zStack(_ overlay: ImageModable?, alignment: UIView.ContentMode = .center) -> ImageModable { + guard let overlay = overlay else { return self } let rect = overlay.canvasSize.align(in: canvasSize, alignment: alignment) return with(overlay .scaled(to: rect.size)