在SwiftUI Xcode beta 5中将带有cornerRadius的边框添加到图像 [英] Add a border with cornerRadius to an Image in SwiftUI Xcode beta 5

查看:121
本文介绍了在SwiftUI Xcode beta 5中将带有cornerRadius的边框添加到图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何为图像添加带有cornerRadius的边框.我收到不赞成使用的警告,说我应该使用RoundedRectange形状,但我不知道该怎么使用

how can I add a border with a cornerRadius to an Image. I get a deprecation warning saying that i should use a RoundedRectange Shape, but i don't know how to use that exactly

测试版4:

Image(uiImage: ...)
   .border(Color.black, width: 2, cornerRadius: 10)

推荐答案

SwiftUI 1.0

使用cornerRadius&重叠修饰符

这是我们可以使用cornerRadius修饰符(剪切视图),然后用颜色覆盖笔触的另一种方法.

SwiftUI 1.0

Using cornerRadius & overlay Modifiers

Here is another way in which we can use a cornerRadius modifier (which clips the view) and then overlay a stroke with a color.

VStack(spacing: 40) {
    Text("Image Border").font(.largeTitle)
    Text("Using cornerRadius & overlay").font(.title).foregroundColor(.gray)
    Text("Using cornerRadius will also clip the image. Then overlay a border.")
        .frame(minWidth: 0, maxWidth: .infinity)
        .font(.title)
        .padding()
        .background(Color.orange)
        .foregroundColor(.black)

    Image("profile")
        .cornerRadius(10)
        .overlay(RoundedRectangle(cornerRadius: 10)
            .stroke(Color.orange, lineWidth: 4))
        .shadow(radius: 10)
}

结果

这篇关于在SwiftUI Xcode beta 5中将带有cornerRadius的边框添加到图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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