swiftui - SwiftUI 按钮图像插图
问题描述
SwiftUI 是否有与 ImageEdgeInsets 相同的东西。例如,我有 60x60 的按钮。并想为里面的图像制作插图。
VStack(alignment: .leading, spacing: 0.0){
Section{
Button(action: {
if self.accountViewModel.signInContext == .quote{
self.presentationMode.wrappedValue.dismiss()
}else{
self.viewController?.dismiss(animated: true)
}
}){
Image("Close Icon").renderingMode(.template).padding(.vertical, 20).padding(.horizontal, 20).foregroundColor(.white).scaledToFit()
}
.frame(width: 60, height: 60)
Rectangle().line().padding(.horizontal, -30)
}
}
解决方案
是的,.padding
就是为了这个目的,只需要使图像可调整大小。我想你需要以下
Image("Close Icon")
.renderingMode(.template)
.resizable()
.aspectRatio(contentMode: .fit)
.padding(.vertical, 20).padding(.horizontal, 20)
推荐阅读
- php - 如何修复未发送的 POST 方法
- java - 如何在 Windows 10 64 位上默认打开 .jar 文件
- mysql - 有没有办法改进这个 SQL 查询以按特定顺序检索数据?
- java - 如何在运行时更改 By class 以生成动态变化的 xpath?
- flutter - 尝试在 Flutter 中使用图像网络而不是图像实体图像时出现错误 解决方法是什么?
- clojure - 数据规则与查询性能
- c++ - 无法将 Glew 与 Cmake 链接
- java - 碎片似乎相互堆叠 - 导致问题,android
- laravel - 与 Laravel 5.8 中的 auth、web 和 guard 中间件有什么区别
- python - 即使使用 selenium 和 python 发生错误,如何使您的代码运行