我正在尝试创建一个小型社交媒体应用程序。到目前为止一切工作正常,但是当我试图显示 an 的长度(这保存了 a中Array的朋友)时,我收到错误UserProfilView"No exact matches in call to initializer"
Capsule()
.frame(width: 110, height: 30)
.offset(x: 40)
.foregroundColor(.blue)
.overlay(
HStack {
Image(systemName: "person.3.fill")
.foregroundColor(.white)
.position(x: 120, y: 15)
Text(appUser.friends.count)
.foregroundColor(.white)
.position(x: 35, y: 15)
.frame(width: 70, height: 30, alignment: .trailing)
}
)
Run Code Online (Sandbox Code Playgroud)
class User: ObservableObject{
@Published var username: String = ""
@Published var name: String = ""
var password: String = ""
@Published var email: String = ""
@Published var beschreibung: String = ""
@Published …Run Code Online (Sandbox Code Playgroud) 我正在取消 UiKit 图像选择器并尝试为用户设置个人资料图片。一切正常,图像显示出来。但我正在努力将其变成一个圆圈。我尝试将 ClipShape 与圆圈一起使用,但它不起作用。我按照教程“我的图像 1:SwiftUI 中的照片选择器和相机”进行操作
struct ProfileView: View {
@EnvironmentObject var appUser: User
@EnvironmentObject var appInfo: AppInformation
var body: some View {
ZStack {
Rectangle()
.frame(width: 400, height: 720)
.cornerRadius(50)
.foregroundColor(.gray)
.overlay(
HStack {
if let image = appUser.profilBild {
Image(uiImage: image)
.resizable()
.frame(width: 100, height: 100)
.scaledToFill()
.clipShape(RoundedRectangle(cornerRadius: 15))
.overlay(Circle().stroke(Color.orange, lineWidth: 10))
.onTapGesture {
appInfo.source = .library
appInfo.showPicker = true
}
.padding(20)
.shadow(radius: 10)
.overlay(
ZStack{
Rectangle()
.frame(width: 20, height: 20)
.offset(x: 35, y: -35)
.foregroundColor(.white)
Image(systemName: …Run Code Online (Sandbox Code Playgroud)