缩放图像以填充后,SwiftUI 边缘变得可见 [英] SwiftUI edges become visible after scaling images to fill

查看:23
本文介绍了缩放图像以填充后,SwiftUI 边缘变得可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 swiftUI 的新手,我一直在尝试将图像放置在圆角矩形中,但每次使用 scaledToFill() 时,矩形的角都消失了.这是我的代码:

I am new to swiftUI and I have been trying to place images in a Rounded rectangle but every time I use scaledToFill() The corners of the rectangle disappear. This is my code :

Image("img_6").resizable()
                
                .scaledToFill()
                .clipShape(RoundedRectangle(cornerRadius: 55,
            style: .continuous))
                .shadow(radius: 9)
                .frame(height: 550).clipped()

推荐答案

修饰符顺序很重要.在您的情况下,只需在 .frame 之后移动 .clipShape,如

Modifiers order is important. In your case just move .clipShape after .frame, as

高:

宽:

    Color.clear
        .frame(height: 550)
        .overlay(Image("img")
            .resizable()
            .scaledToFill())
        .clipShape(RoundedRectangle(cornerRadius: 55,
            style: .continuous))
        .shadow(radius: 9)

注意:.clipped 不需要,因为.clipShape 已经进行了裁剪

Note: .clipped not needed, because .clipShape already performs clipping

这篇关于缩放图像以填充后,SwiftUI 边缘变得可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆